Class: Oso::Polar::FFI::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/oso/polar/ffi/error.rb

Overview

Wrapper class for Error FFI pointer + operations.

Class Method Summary collapse

Class Method Details

.get(error_str, enrich_message) ⇒ ::Oso::Polar::Error, ::Oso::Polar::FFIErrorNotFound

Check for an FFI error and convert it into a Ruby exception.

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oso/polar/ffi/error.rb', line 14

def self.get(error_str, enrich_message) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
  error = JSON.parse(error_str.to_s)
  msg = error['formatted']
  kind, body = error['kind'].first

  # Not all errors have subkind and details.
  # TODO (gj): This bug may exist in other libraries.
  if body.is_a? Hash
    subkind, details = body.first
  else
    subkind, details = nil
  end

  # Enrich error message and stack trace
  msg = enrich_message.call(msg) if msg
  if details
    details['stack_trace'] = enrich_message.call(details['stack_trace']) if details['stack_trace']
    details['msg'] = enrich_message.call(details['msg']) if details['msg']
  end

  case kind
  when 'Parse'
    parse_error(subkind, msg: msg, details: details)
  when 'Runtime'
    runtime_error(subkind, msg: msg, details: details)
  when 'Operational'
    operational_error(subkind, msg: msg, details: details)
  when 'Validation'
    validation_error(msg, details: details)
  end
end