• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

BetterErrors / better_errors / 461 / 63

Source File

84.21
/lib/better_errors/raised_exception.rb
1
# @private
2
module BetterErrors
1✔
3
  class RaisedException
1✔
4
    attr_reader :exception, :message, :backtrace
1✔
5

6
    def initialize(exception)
1✔
7
      if exception.respond_to?(:cause)
38✔
8
        exception = exception.cause if exception.cause
36✔
9
      elsif exception.respond_to?(:original_exception) && exception.original_exception
2✔
10
        exception = exception.original_exception
2✔
11
      end
12

13
      @exception = exception
38✔
14
      @message = exception.message
38✔
15

16
      setup_backtrace
38✔
17
      massage_syntax_error
38✔
18
    end
19

20
    def type
1✔
21
      exception.class
23✔
22
    end
23

24
  private
1✔
25
    def has_bindings?
1✔
26
      exception.respond_to?(:__better_errors_bindings_stack) && exception.__better_errors_bindings_stack.any?
38✔
27
    end
28

29
    def setup_backtrace
1✔
30
      if has_bindings?
38✔
31
        setup_backtrace_from_bindings
×
32
      else
33
        setup_backtrace_from_backtrace
38✔
34
      end
35
    end
36

37
    def setup_backtrace_from_bindings
1✔
38
      @backtrace = exception.__better_errors_bindings_stack.map { |binding|
×
39
        file = binding.eval "__FILE__"
×
40
        line = binding.eval "__LINE__"
×
41
        name = binding.frame_description
×
42
        StackFrame.new(file, line, name, binding)
×
43
      }
44
    end
45

46
    def setup_backtrace_from_backtrace
1✔
47
      @backtrace = (exception.backtrace || []).map { |frame|
38✔
48
        if /\A(?<file>.*?):(?<line>\d+)(:in `(?<name>.*)')?/ =~ frame
696✔
49
          StackFrame.new(file, line.to_i, name)
695✔
50
        end
51
      }.compact
52
    end
53

54
    def massage_syntax_error
1✔
55
      case exception.class.to_s
38✔
56
      when "Haml::SyntaxError", "Sprockets::Coffeelint::Error"
57
        if /\A(.+?):(\d+)/ =~ exception.backtrace.first
6✔
58
          backtrace.unshift(StackFrame.new($1, $2.to_i, ""))
6✔
59
        end
60
      when "SyntaxError"
61
        if /\A(.+?):(\d+): (.*)/m =~ exception.message
4✔
62
          backtrace.unshift(StackFrame.new($1, $2.to_i, ""))
3✔
63
          @message = $3
3✔
64
        end
65
      end
66
    end
67
  end
68
end
  • Back to Build 446
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc