* 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.
This commit is contained in:
Mark A. Miller 2011-08-14 08:03:43 -05:00
parent 01544701aa
commit f3e2c939f4
2 changed files with 8 additions and 2 deletions

View File

@ -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'

View File

@ -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