Skip to content

Commit

Permalink
Merge pull request #454 from urbanopt/rescue
Browse files Browse the repository at this point in the history
adding rescue blocks to catch errors
  • Loading branch information
kflemin authored Mar 11, 2024
2 parents b0f481d + d6803ab commit b191196
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/uo_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def initialize
send("opt_#{@command}") ## dispatch to command handling method
rescue NoMethodError
abort('Invalid command, please run uo --help for a list of available commands')
rescue => error
puts "\nERROR: #{error.message}"
end
end

Expand Down Expand Up @@ -438,6 +440,8 @@ def opt_ghe_size
end
rescue NoMethodError
abort('Invalid command, please run uo --help for a list of available commands')
rescue => error
puts "\nERROR: #{error.message}"
end

# FIXME: Can this be combined with the above block? This isn't very DRY
Expand Down Expand Up @@ -509,6 +513,8 @@ def self.create_scenario_csv_file(feature_id)
# Rescue if file isn't json
rescue JSON::ParserError => e
abort("\nOops! You didn't provide a json file. Please provide path to the geojson feature_file")
rescue => error
puts "\nERROR: #{error.message}"
end
Dir["#{@feature_path}/mappers/*.rb"].each do |mapper_file|
mapper_name = File.basename(mapper_file, File.extname(mapper_file))
Expand Down Expand Up @@ -536,6 +542,8 @@ def self.create_scenario_csv_file(feature_id)
# Rescue if json isn't a geojson feature_file
rescue NoMethodError
abort("\nOops! You didn't provde a valid feature_file. Please provide path to the geojson feature_file")
rescue => error
puts "\nERROR: #{error.message}"
end
end
end
Expand Down Expand Up @@ -1293,6 +1301,8 @@ def self.install_python_dependencies
end
rescue Errno::ENOENT # Same abort message if there is no run_dir
abort("ERROR: URBANopt simulations are required before using opendss. Please run and process simulations, then try again.\n")
rescue => error
puts "\nERROR: #{error.message}"
end

ditto_cli_root = "#{res[:pvars][:ditto_path]} run-opendss "
Expand Down Expand Up @@ -1336,6 +1346,8 @@ def self.install_python_dependencies
rescue FileNotFoundError
abort("\nMust post-process results before running OpenDSS. We recommend 'process --default'." \
"Once OpenDSS is run, you may then 'process --opendss'")
rescue => error
puts "\nERROR: #{error.message}"
end
end

Expand Down Expand Up @@ -1441,6 +1453,8 @@ def self.install_python_dependencies
runner.post_process
rescue StandardError => e
abort("\nError: #{e.message}")
rescue => error
puts "\nERROR: #{error.message}"
end

# TODO: aggregate back into scenario reports and geojson file
Expand Down Expand Up @@ -1526,7 +1540,8 @@ def self.install_python_dependencies
if feature[:properties][:district_system_type] && (feature[:properties][:district_system_type] == 'Community Photovoltaic')
community_photovoltaic << feature
end
rescue StandardError
rescue => error
puts "\nERROR: #{error.message}"
end
reopt_post_processor = URBANopt::REopt::REoptPostProcessor.new(
scenario_report,
Expand All @@ -1553,7 +1568,8 @@ def self.install_python_dependencies
if feature[:properties][:district_system_type] && (feature[:properties][:district_system_type] == 'Ground Mount Photovoltaic')
groundmount_photovoltaic[feature[:properties][:associated_building_id]] = feature[:properties][:footprint_area]
end
rescue StandardError
rescue => error
puts "\nERROR: #{error.message}"
end
scenario_report_features = reopt_post_processor.run_scenario_report_features(
scenario_report: scenario_report,
Expand Down Expand Up @@ -1771,6 +1787,8 @@ def self.install_python_dependencies
system(des_cli_root + des_cli_addition)
rescue FileNotFoundError
abort("\nMust simulate using 'uo run' before preparing Modelica models.")
rescue => error
puts "\nERROR: #{error.message}"
end
end

Expand Down Expand Up @@ -1803,6 +1821,8 @@ def self.install_python_dependencies
system(des_cli_root + des_cli_addition)
rescue FileNotFoundError
abort("\nMust simulate using 'uo run' before preparing Modelica models.")
rescue => error
puts "\nERROR: #{error.message}"
end
end

Expand All @@ -1825,6 +1845,8 @@ def self.install_python_dependencies
system(des_cli_root + des_cli_addition)
rescue FileNotFoundError
abort("\nMust simulate using 'uo run' before preparing Modelica models.")
rescue => error
puts "\nERROR: #{error.message}"
end
end

Expand Down Expand Up @@ -1872,6 +1894,8 @@ def self.install_python_dependencies
system(ghe_cli_root + ghe_cli_addition)
rescue FileNotFoundError
abort("\nFile Not Found Error Holder.")
rescue => error
puts "\nERROR: #{error.message}"
end

end
Expand Down

0 comments on commit b191196

Please sign in to comment.