Class: Bosh::Agent::RemoteException
- Defined in:
- lib/bosh_agent/remote_exception.rb
Overview
Helper class to pass around and fromat exceptions in the agent to the director
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#blob ⇒ Object
readonly
Returns the value of attribute blob.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Class Method Summary collapse
-
.from(exception) ⇒ Bosh::Agent::RemoteException
Helper class method that creates a [Bosh::Agent::RemoteException] from an [Exception].
Instance Method Summary collapse
-
#initialize(message, backtrace = nil, blob = nil) ⇒ RemoteException
constructor
A new instance of RemoteException.
- #logger ⇒ Object
-
#store_blob ⇒ String
Stores the blob in the configured blobstore.
-
#to_hash ⇒ Hash
Returns a hash of the [RemoteException] suitable to convert to json.
Constructor Details
#initialize(message, backtrace = nil, blob = nil) ⇒ RemoteException
Returns a new instance of RemoteException.
8 9 10 11 12 |
# File 'lib/bosh_agent/remote_exception.rb', line 8 def initialize(, backtrace=nil, blob=nil) @message = @backtrace = backtrace.nil? ? caller : backtrace @blob = blob end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
6 7 8 |
# File 'lib/bosh_agent/remote_exception.rb', line 6 def backtrace @backtrace end |
#blob ⇒ Object (readonly)
Returns the value of attribute blob.
6 7 8 |
# File 'lib/bosh_agent/remote_exception.rb', line 6 def blob @blob end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/bosh_agent/remote_exception.rb', line 6 def @message end |
Class Method Details
.from(exception) ⇒ Bosh::Agent::RemoteException
Helper class method that creates a [Bosh::Agent::RemoteException] from an [Exception]
53 54 55 56 57 58 59 |
# File 'lib/bosh_agent/remote_exception.rb', line 53 def self.from(exception) blob = nil if exception.instance_of?(Bosh::Agent::MessageHandlerError) blob = exception.blob end self.new(exception., exception.backtrace, blob) end |
Instance Method Details
#logger ⇒ Object
45 46 47 |
# File 'lib/bosh_agent/remote_exception.rb', line 45 def logger Bosh::Agent::Config.logger end |
#store_blob ⇒ String
Stores the blob in the configured blobstore
string which can be displayed instead of the blob
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bosh_agent/remote_exception.rb', line 18 def store_blob = Bosh::Agent::Config. bsc_provider = Bosh::Agent::Config.blobstore_provider blobstore = Bosh::Blobstore::Client.create(bsc_provider, ) logger.info("Uploading blob for '#{@message}' to blobstore") blobstore_id = nil blobstore_id = blobstore.create(@blob) blobstore_id rescue Bosh::Blobstore::BlobstoreError => e logger.warn("unable to upload blob for '#{@message}'") "error: unable to upload blob to blobstore: #{e.}" end |
#to_hash ⇒ Hash
Returns a hash of the [RemoteException] suitable to convert to json
38 39 40 41 42 43 |
# File 'lib/bosh_agent/remote_exception.rb', line 38 def to_hash hash = {:message => @message} hash[:backtrace] = @backtrace hash[:blobstore_id] = store_blob if @blob {:exception => hash} end |