From d6803ab6ef5bcf1f5955046d648193d6113b0fdb Mon Sep 17 00:00:00 2001 From: kflemin <2205659+kflemin@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:54:50 -0700 Subject: [PATCH] adding rescue blocks to catch errors --- lib/uo_cli.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/uo_cli.rb b/lib/uo_cli.rb index 54ef24b6..815b265c 100755 --- a/lib/uo_cli.rb +++ b/lib/uo_cli.rb @@ -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 @@ -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 @@ -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)) @@ -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 @@ -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 " @@ -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 @@ -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 @@ -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, @@ -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, @@ -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 @@ -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 @@ -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 @@ -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