Sha256: 8ee4d369a7aa7a9011ffacc0b4729579782e16dd5d231be828bad12d486f6a6a

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

module PipeRpc
  class Hub::Responder::Request
    class Error
      def initialize(error)
        @error = error
      end

      attr_reader :error

      def code
        case @error
        when NoServerError then -32604
        when method_call_error? && NoMethodError then -32601
        when method_call_error? && ArgumentError then -32602
        when InternalError then -32605
        when StandardError then -32603
        else nil
        end
      end

      def message
        @error.message
      end

      def backtrace
        @error.backtrace.to_a.dup.tap do |backtrace|
          # In ruby, backtraces of argument errors have the location of the
          # method definition and not from where it is called as first location
          # in the backtrace. To normalize argument and no method errors,
          # remove the first location for argument errors.
          backtrace.shift if @error.is_a?(ArgumentError) and not Object.const_defined?(:MRUBY_VERSION)
        end
      end

      def method_call_error?
        if Object.const_defined?(:MRUBY_VERSION)
          backtrace.first.nil?
        else
          backtrace.first.split(':').first(2) == [CALL_FILE, CALL_LINENO.to_s]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pipe_rpc-0.3.2 lib/pipe_rpc/hub/responder/request/error.rb
pipe_rpc-0.3.1 lib/pipe_rpc/hub/responder/request/error.rb
pipe_rpc-0.3.0 lib/pipe_rpc/hub/responder/request/error.rb
pipe_rpc-0.2.2 lib/pipe_rpc/hub/responder/request/error.rb