Sha256: 3c1a5d1c0686d9d5b8c7d60bd594074f47aff42eaf7edf0103c270567f09823e
Contents?: true
Size: 1.31 KB
Versions: 7
Compression:
Stored size: 1.31 KB
Contents
module Nodo class Error < StandardError; end class TimeoutError < Error; end class CallError < Error; end class JavaScriptError < Error attr_reader :attributes def initialize(attributes = {}, function = nil) @attributes = attributes || {} if backtrace = generate_backtrace(attributes['stack']) backtrace.unshift function.source_location if function && function.source_location set_backtrace backtrace end @message = generate_message end def to_s @message end private # "filename:lineNo: in `method''' or “filename:lineNo.'' def generate_backtrace(stack) backtrace = [] if stack and lines = stack.split("\n") lines.shift lines.each do |line| if match = line.match(/\A *at (?<call>.+) \((?<src>.*):(?<line>\d+):(?<column>\d+)\)/) backtrace << "#{match[:src]}:#{match[:line]}:in `#{match[:call]}'" end end end backtrace unless backtrace.empty? end def generate_message message = "#{attributes['message'] || 'Unknown error'}" if loc = attributes['loc'] message << loc.inject(' in') { |s, (key, value)| s << " #{key}: #{value}" } end message end end class DependencyError < JavaScriptError; end end
Version data entries
7 entries across 7 versions & 1 rubygems