dyoder / befog

Command line utility for cloud management
MIT License
4 stars 4 forks source link

Add better error handling for invalid config files #22

Open dyoder opened 12 years ago

automatthew commented 12 years ago
diff --git a/lib/befog/commands/mixins/configurable.rb b/lib/befog/commands/mixins/configurable.rb
index c045376..9374527 100644
--- a/lib/befog/commands/mixins/configurable.rb
+++ b/lib/befog/commands/mixins/configurable.rb
@@ -23,7 +23,19 @@ module Befog
         end

         def _configuration
-          @configuration ||= (YAML.load_file(configuration_path) rescue {})
+          if @configuration
+            @configuration
+          else
+            begin
+              @configuration = YAML.load_file(configuration_path)
+            rescue Errno::ENOENT
+              $stdout.puts "No such file: #{configuration_path}"
+              exit
+            rescue => e
+              $stdout.puts "Problem reading configuration file: #{e.inspect}"
+              exit
+            end
+          end
         end

         def configuration
@@ -43,4 +55,4 @@ module Befog
       end
     end
   end
-end
\ No newline at end of file
+end