Sha256: 8351a75fa99688974591022ef6223d3c50ca2cc68416085dc58ec31075698739

Contents?: true

Size: 1.1 KB

Versions: 18

Compression:

Stored size: 1.1 KB

Contents

module Skylight
  class NativeError < StandardError

    @@classes = { }

    def self.register(code, name, message)
      if @@classes.has_key?(code)
        raise "Duplicate error class code: #{code}; name=#{name}"
      end

      Skylight.module_eval <<-ruby
        class #{name}Error < NativeError
          def self.code; #{code}; end
          def self.message; #{message.to_json}; end
        end
      ruby

      klass = Skylight.const_get("#{name}Error")

      @@classes[code] = klass
    end

    def self.for_code(code)
      @@classes[code] || self
    end

    attr_reader :method_name

    def self.code
      9999
    end

    def self.message
      "Encountered an unknown internal error"
    end

    def initialize(method_name)
      @method_name = method_name
      super(sprintf("[E%04d] %s [%s]", code, message, method_name))
    end

    def code
      self.class.code
    end

    def formatted_code
      "%04d" % code
    end

    # E0003
    register(3, "MaximumTraceSpans", "Exceeded maximum number of spans in a trace.")

    # E0004
    register(4, "SqlLex", "Failed to lex SQL query.")
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
skylight-3.1.5 lib/skylight/errors.rb
skylight-3.1.4 lib/skylight/errors.rb
skylight-3.1.3 lib/skylight/errors.rb
skylight-3.1.3.beta lib/skylight/errors.rb
skylight-3.1.2 lib/skylight/errors.rb
skylight-3.1.1 lib/skylight/errors.rb
skylight-3.1.0 lib/skylight/errors.rb
skylight-3.1.0.beta3 lib/skylight/errors.rb
skylight-3.1.0.beta2 lib/skylight/errors.rb
skylight-3.1.0.beta lib/skylight/errors.rb
skylight-3.0.0 lib/skylight/errors.rb
skylight-3.0.0.beta lib/skylight/errors.rb
skylight-2.0.2 lib/skylight/errors.rb
skylight-2.0.2.beta.1 lib/skylight/errors.rb
skylight-2.0.2.beta lib/skylight/errors.rb
skylight-2.0.1 lib/skylight/errors.rb
skylight-2.0.0 lib/skylight/errors.rb
skylight-2.0.0.beta3 lib/skylight/errors.rb