Class: Sevgi::Executor::Error

Inherits:
Sevgi::Error
  • Object
show all
Defined in:
lib/sevgi/executor/error.rb

Overview

Wraps an exception raised while executing Sevgi script source. Its visited source snapshot records every source in load order; it is not the active load stack at the instant of failure.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, stack) ⇒ void

Builds an executor error wrapper.

Parameters:

  • error (Exception)

    original exception

  • stack (Array<String>)

    source file keys visited in load order; the Array and its String entries are copied and frozen



19
20
21
22
23
24
# File 'lib/sevgi/executor/error.rb', line 19

def initialize(error, stack)
  @cause = error
  @stack = stack.map { it.dup.freeze }.freeze

  super(error.message)
end

Instance Attribute Details

#causeException (readonly)

Returns the original exception as the wrapped cause.

Returns:

  • (Exception)


39
40
41
# File 'lib/sevgi/executor/error.rb', line 39

def cause
  @cause
end

Instance Method Details

#load_backtraceArray<String>

Returns backtrace entries that belong to the visited Sevgi source set.

Returns:

  • (Array<String>)

    filtered backtrace lines relative to the current directory, or an empty Array when the original exception has no backtrace



29
30
31
32
33
34
35
# File 'lib/sevgi/executor/error.rb', line 29

def load_backtrace
  sources = @stack.map { ::File.expand_path(it) }

  Array(cause.backtrace)
    .select { sources.include?(::File.expand_path(it.split(":", 2).first)) }
    .map { |line| line.delete_prefix("#{::Dir.pwd}/") }
end