Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* 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.
  • Loading branch information...
commit f3e2c939f40765faa8c4ca29d24d31741c645667 1 parent 0154470
Mark A. Miller authored

Showing 2 changed files with 8 additions and 2 deletions. Show diff stats Hide diff stats

  1. +5 1 bin/fog
  2. +3 1 lib/fog/core/errors.rb
6 bin/fog
@@ -5,7 +5,11 @@ require 'yaml'
5 5 Fog.credential = ARGV.first ? ARGV.first.to_sym : nil
6 6 Fog.mock! if ENV['FOG_MOCK']
7 7 if Fog.credentials.empty?
8   - Fog::Errors.missing_credentials
  8 + begin
  9 + Fog::Errors.missing_credentials
  10 + rescue Fog::Errors::LoadError => error
  11 + abort error.message
  12 + end
9 13 end
10 14
11 15 require 'fog/bin'
4 lib/fog/core/errors.rb
@@ -16,6 +16,8 @@ class MockNotImplemented < Fog::Errors::Error; end
16 16
17 17 class NotFound < Fog::Errors::Error; end
18 18
  19 + class LoadError < LoadError; end
  20 +
19 21 # @return [String] The error message that will be raised, if credentials cannot be found
20 22 def self.missing_credentials
21 23 missing_credentials_message = <<-YML
@@ -68,7 +70,7 @@ def self.missing_credentials
68 70 #######################################################
69 71
70 72 YML
71   - raise(LoadError.new(missing_credentials_message))
  73 + raise(Fog::Errors::LoadError.new(missing_credentials_message))
72 74 end
73 75
74 76 end

0 comments on commit f3e2c93

Please sign in to comment.
Something went wrong with that request. Please try again.