Module: Low::ErrorHandling

Included in:
LocalProxy, Lowkey::ParamProxy, Lowkey::ReturnProxy
Defined in:
lib/interfaces/error_handling.rb

Overview

Used by proxies to output errors.

Instance Method Summary collapse

Instance Method Details

#backtrace(backtrace:, hidden_paths:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/interfaces/error_handling.rb', line 26

def backtrace(backtrace:, hidden_paths:)
  # Remove LowType defined method file paths from the backtrace.
  filtered_backtrace = backtrace.reject { |line| hidden_paths.find { |file_path| line.include?(file_path) } }

  # Add the proxied entity to the backtrace.
  proxy_file_backtrace = "#{file_path}:#{start_line}:in '#{scope}'"
  from_prefix = filtered_backtrace.first.match(/\s+from /)
  proxy_file_backtrace = "#{from_prefix}#{proxy_file_backtrace}" if from_prefix

  [proxy_file_backtrace, *filtered_backtrace]
end

#error_message(value:) ⇒ Object

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/interfaces/error_handling.rb', line 10

def error_message(value:)
  raise NotImplementedError
end

#error_typeObject

Raises:

  • (NotImplementedError)


6
7
8
# File 'lib/interfaces/error_handling.rb', line 6

def error_type
  raise NotImplementedError
end

#output(value:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/interfaces/error_handling.rb', line 14

def output(value:)
  case LowType.config.output_mode
  when :type
    # TODO: Show full type structure in error output instead of just the type of the supertype.
    value.class
  when :value
    value.inspect[0...LowType.config.output_size]
  else
    'REDACTED'
  end
end