Sha256: fe9ab637ec83457f980c8b3aa7190a9f52bf43ec830e28b54824b49a7956a4fc

Contents?: true

Size: 1.62 KB

Versions: 39

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8

module OneApm
  module Support
    class Marshaller

      # Used to wrap errors reported to agent by the collector
      class CollectorError < StandardError; end

      def parsed_error(error)
        error_type    = error['error_type']
        error_message = error['message']

        exception = case error_type
        when 'OneApm::LicenseException'
          OneApm::LicenseException.new(error_message)
        when 'OneApm::ForceRestartException'
          OneApm::ForceRestartException.new(error_message)
        when 'OneApm::ForceDisconnectException'
          OneApm::ForceDisconnectException.new(error_message)
        else
          OneApm::Support::Marshaller::CollectorError.new("#{error['error_type']}: #{error['message']}")
        end

        exception
      end

      def prepare(data, options={})
        encoder = options[:encoder] || default_encoder
        if data.respond_to?(:to_collector_array)
          data.to_collector_array(encoder)
        elsif data.kind_of?(Array)
          data.map { |element| prepare(element, options) }
        else
          data
        end
      end

      def default_encoder
        Encoders::Identity
      end

      def self.human_readable?
        false
      end

      protected

      def return_value(data)
        if data.respond_to?(:has_key?)
          if data.has_key?('exception')
            raise parsed_error(data['exception'])
          elsif data.has_key?('return_value')
            return data['return_value']
          end
        end
        OneApm::Manager.logger.debug("Unexpected response from collector: #{data}")
        nil
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
oneapm_rpm-1.2.9.rc1 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.8 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.8.rc1 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.7 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.7.rc1 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.6 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.6.rc1 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.5 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.5.rc1 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.4 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.4.rc1 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.3 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.3.rc2 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.2 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.2.rc lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.1 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.1.rc lib/one_apm/support/marshaller.rb
oneapm_rpm-1.2.0 lib/one_apm/support/marshaller.rb
oneapm_rpm-1.1.3 lib/one_apm/support/marshaller.rb