From f3e2c939f40765faa8c4ca29d24d31741c645667 Mon Sep 17 00:00:00 2001 From: "Mark A. Miller" Date: Sun, 14 Aug 2011 08:03:43 -0500 Subject: [PATCH] * Changed LoadError to Fog::Error::LoadError when missing configuration * When running from command line, rescue the exception, and print the help message When running fog for the first time with no setup, the missing_exception message was surrounded above and below with a stack trace, which is not particularly user-friendly. Since we've rescuing the LoadError only in bin/fog, we know we don't have to worry about higher level libraries not getting the exception, since it wouldn't propagate between processes. Changing LoadError to Fog::Error::LoadError lets us know that this was an issue on fog's part, rather than some other library we might be using. Since we inherit from the LoadError class, any higher-level libraries that were using a rescue based on LoadError will still work. --- bin/fog | 6 +++++- lib/fog/core/errors.rb | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/fog b/bin/fog index 9fd7ae58a..06876156f 100755 --- a/bin/fog +++ b/bin/fog @@ -5,7 +5,11 @@ require 'yaml' Fog.credential = ARGV.first ? ARGV.first.to_sym : nil Fog.mock! if ENV['FOG_MOCK'] if Fog.credentials.empty? - Fog::Errors.missing_credentials + begin + Fog::Errors.missing_credentials + rescue Fog::Errors::LoadError => error + abort error.message + end end require 'fog/bin' diff --git a/lib/fog/core/errors.rb b/lib/fog/core/errors.rb index 31cf2c6b5..747291a9a 100644 --- a/lib/fog/core/errors.rb +++ b/lib/fog/core/errors.rb @@ -16,6 +16,8 @@ module Fog class NotFound < Fog::Errors::Error; end + class LoadError < LoadError; end + # @return [String] The error message that will be raised, if credentials cannot be found def self.missing_credentials missing_credentials_message = <<-YML @@ -68,7 +70,7 @@ An alternate file may be used by placing its path in the FOG_RC environment vari ####################################################### YML - raise(LoadError.new(missing_credentials_message)) + raise(Fog::Errors::LoadError.new(missing_credentials_message)) end end