Exception: Krill::KrillBaseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/krill/protocol_sandbox.rb

Direct Known Subclasses

KrillError, KrillSyntaxError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation_type:, error:, message:, namespace: '') ⇒ KrillBaseError

Create a KrillBaseError object for the given operation type, error and message.

Parameters:

  • operation_type (OperationType)

    the operation type

  • error (Exception)

    the error object

  • message (string)

    the message for this error



151
152
153
154
155
156
# File 'lib/krill/protocol_sandbox.rb', line 151

def initialize(operation_type:, error:, message:, namespace: '')
  @operation_type = operation_type
  @error = error
  @namespace = namespace
  super(message)
end

Instance Attribute Details

#errorObject (readonly)



144
145
146
# File 'lib/krill/protocol_sandbox.rb', line 144

def error
  @error
end

#namespaceObject (readonly)



144
145
146
# File 'lib/krill/protocol_sandbox.rb', line 144

def namespace
  @namespace
end

#operation_typeObject (readonly)



144
145
146
# File 'lib/krill/protocol_sandbox.rb', line 144

def operation_type
  @operation_type
end

Instance Method Details

#error_backtraceObject

Returns the backtrace of the associated error filtered to exclude Aquarium context. Replaces occurrences of '(eval)' path with operation type path.



196
197
198
199
200
201
202
203
204
205
# File 'lib/krill/protocol_sandbox.rb', line 196

def error_backtrace
  split = error.backtrace.collect { |msg| msg.match(/^([^:]+):(\d+):(.+)$/m).captures }
  filtered = split.reject { |c| c.first.match(%r{^(/[^/]+)+$}m) }
  filtered.collect do |captures|
    path, line_number, message = captures
    path = operation_path if path == '(eval)'

    "#{path}: line #{line_number}: #{message.strip}".strip
  end
end

#error_messageObject

Returns a transformed version of the message for the error of this object. Replaces occurrences of "(eval)" with the operation type path, and removes suffix referencing ExecutionNamespace enclosing the protocol during execution.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/krill/protocol_sandbox.rb', line 167

def error_message
  messages = []
  @error.message.each_line do |line|
    # replaces occurrence of "(eval)" as file path
    match = line.match(/^\(eval\):(\d+):(.+)$/m)
    if match
      line_number, message = match.captures
      messages.append("#{operation_path}: line #{line_number}:#{message}")
      next
    end

    # strips uninformative context from NameError message
    namespace_pattern = Regexp.new(" for (\#<)?#{@namespace}:(Module|0x[0-9a-f]+>)$")
    match = line.match(namespace_pattern)
    if match
      loc = match.begin(0) - 1
      messages.append(line[0..loc])
      next
    end

    messages.append(line)
  end

  messages.join('')
end

#operation_pathObject

Returns the path of the operation type for this error.



159
160
161
# File 'lib/krill/protocol_sandbox.rb', line 159

def operation_path
  "#{@operation_type.category}/#{@operation_type.name}"
end