Exception: Sfn::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Sfn::Error
- Defined in:
- lib/sfn/error.rb
Direct Known Subclasses
InteractionDisabled, StackNotFound, StackPlanNotFound, StackStateIncomplete
Defined Under Namespace
Classes: InteractionDisabled, StackNotFound, StackPlanNotFound, StackStateIncomplete
Constant Summary collapse
- DEFAULT_EXIT_CODE =
Exit code used when no custom code provided
1
Instance Attribute Summary collapse
-
#exit_code ⇒ Integer
readonly
Exit code to report.
-
#original ⇒ Exception?
readonly
Original exception.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(*args) ⇒ Error
Returns a new instance of Error.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sfn/error.rb', line 25 def initialize(*args) opts = args.detect { |a| a.is_a?(Hash) } || {} opts = opts.to_smash msg = args.first.is_a?(String) ? args.first : self.class.error_msg super(msg) @exit_code = opts.fetch(:exit_code, self.class.exit_code).to_i if opts[:original] if opts[:original].is_a?(Exception) @original = opts[:original] else raise TypeError.new "Expected `Exception` type in `:original` " \ "option but received `#{opts[:original].class}`" end end end |
Instance Attribute Details
#exit_code ⇒ Integer (readonly)
Returns exit code to report.
4 5 6 |
# File 'lib/sfn/error.rb', line 4 def exit_code @exit_code end |
#original ⇒ Exception? (readonly)
Returns original exception.
6 7 8 |
# File 'lib/sfn/error.rb', line 6 def original @original end |
Class Method Details
.error_msg(m = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/sfn/error.rb', line 18 def self.error_msg(m = nil) if m || !defined?(@error_msg) @error_msg = m end @error_msg end |
.exit_code(c = nil) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/sfn/error.rb', line 11 def self.exit_code(c = nil) if c || !defined?(@exit_code) @exit_code = c.to_i != 0 ? c : DEFAULT_EXIT_CODE end @exit_code end |