Module: Errbit::Backtrace
- Defined in:
- lib/errbit/backtrace.rb
Constant Summary collapse
- LINE_PATTERN =
Matches both backtrace line formats Ruby has used:
"file.rb:12:in `method'" (Ruby <= 3.3) "file.rb:12:in 'method'" (Ruby >= 3.4)and lines with no method info at all: "file.rb:12"
/\A(?<file>.+):(?<line>\d+)(?::in\s+[`'](?<method>.+)')?\z/.freeze
Class Method Summary collapse
Class Method Details
.parse(exception) ⇒ Object
13 14 15 |
# File 'lib/errbit/backtrace.rb', line 13 def parse(exception) Array(exception&.backtrace).map { |line| parse_line(line) } end |
.parse_line(line) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/errbit/backtrace.rb', line 17 def parse_line(line) match = LINE_PATTERN.match(line.to_s) return { file: line.to_s, line: nil, method: nil } unless match { file: match[:file], line: match[:line].to_i, method: match[:method] } end |