Exception: MultiJSON::AdapterError

Inherits:
ArgumentError
  • Object
show all
Defined in:
lib/multi_json/adapter_error.rb

Overview

Raised when an adapter cannot be loaded or is not recognized

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, cause: nil) ⇒ AdapterError

Create a new AdapterError

Examples:

AdapterError.new("Unknown adapter", cause: original_error)

Parameters:

  • message (String, nil) (defaults to: nil)

    error message

  • cause (Exception, nil) (defaults to: nil)

    the original exception



16
17
18
19
# File 'lib/multi_json/adapter_error.rb', line 16

def initialize(message = nil, cause: nil)
  super(message)
  set_backtrace(cause.backtrace) if cause
end

Class Method Details

.build(original_exception) ⇒ AdapterError

Build an AdapterError from an original exception

The original exception’s class name is included in the message so a downstream consumer reading just the AdapterError can tell whether the underlying failure was a ‘LoadError`, an `ArgumentError` from the spec validator, or some other class without having to look at `error.cause` separately.

Examples:

AdapterError.build(LoadError.new("cannot load such file"))

Parameters:

  • original_exception (Exception)

    the original load error

Returns:



34
35
36
37
38
39
40
# File 'lib/multi_json/adapter_error.rb', line 34

def self.build(original_exception)
  new(
    "Did not recognize your adapter specification " \
    "(#{original_exception.class}: #{original_exception.message}).",
    cause: original_exception
  )
end