Module: BetterErrors

Defined in:
lib/better_errors.rb,
lib/better_errors/repl.rb,
lib/better_errors/rails.rb,
lib/better_errors/version.rb,
lib/better_errors/repl/pry.rb,
lib/better_errors/repl/basic.rb,
lib/better_errors/middleware.rb,
lib/better_errors/error_page.rb,
lib/better_errors/stack_frame.rb,
lib/better_errors/code_formatter.rb,
lib/better_errors/code_formatter/text.rb,
lib/better_errors/code_formatter/html.rb

Defined Under Namespace

Classes: Middleware

Constant Summary

VERSION =
"0.6.0"

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (String) application_root

The path to the root of the application. Better Errors uses this property to determine if a file in a backtrace should be considered an application frame. If you are using Better Errors with Rails, you do not need to set this attribute manually.

Returns:

  • (String)


21
22
23
# File 'lib/better_errors.rb', line 21

def application_root
  @application_root
end

+ (Logger?) logger

The logger to use when logging exception details and backtraces. If you are using Better Errors with Rails, you do not need to set this attribute manually. If this attribute is nil, nothing will be logged.

Returns:

  • (Logger, nil)


28
29
30
# File 'lib/better_errors.rb', line 28

def logger
  @logger
end

Class Method Details

+ (Proc) editor

Returns a proc, which when called with a filename and line number argument, returns a URL to open the filename and line in the selected editor.

Generates TextMate URLs by default.

BetterErrors.editor["/some/file", 123] # => txmt://open?url=file:///some/file&line=123

Returns:

  • (Proc)


46
47
48
# File 'lib/better_errors.rb', line 46

def self.editor
  @editor
end

+ (Object) BetterErrors.editor=(sym) + (Object) BetterErrors.editor=(str) + (Object) BetterErrors.editor=(proc)

Configures how Better Errors generates open-in-editor URLs.

Overloads:

  • + (Object) BetterErrors.editor=(sym)

    Uses one of the preset editor configurations. Valid symbols are:

    • :textmate, :txmt, :tm
    • :sublime, :subl, :st
    • :macvim

    Parameters:

    • sym (Symbol)
  • + (Object) BetterErrors.editor=(str)

    Uses str as the format string for generating open-in-editor URLs.

    Use %{file} and %{line} as placeholders for the actual values.

    Examples:

    BetterErrors.editor = "my-editor://open?url=%{file}&line=%{line}"

    Parameters:

    • str (String)
  • + (Object) BetterErrors.editor=(proc)

    Uses proc to generate open-in-editor URLs. The proc will be called with file and line parameters when a URL needs to be generated.

    Your proc should take care to escape file appropriately with URI.encode_www_form_component (please note that URI.escape is not a suitable substitute.)

    Examples:

    BetterErrors.editor = proc { |file, line|
      "my-editor://open?url=#{URI.encode_www_form_component file}&line=#{line}"
    }

    Parameters:

    • proc (Proc)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/better_errors.rb', line 86

def self.editor=(editor)
  case editor
  when :textmate, :txmt, :tm
    self.editor = "txmt://open?url=file://%{file}&line=%{line}"
  when :sublime, :subl, :st
    self.editor = "subl://open?url=file://%{file}&line=%{line}"
  when :macvim, :mvim
    self.editor = proc { |file, line| "mvim://open?url=file://#{file}&line=#{line}" }
  when :emacs
    self.editor = "emacs://open?url=file://%{file}&line=%{line}"
  when String
    self.editor = proc { |file, line| editor % { file: URI.encode_www_form_component(file), line: line } }
  else
    if editor.respond_to? :call
      @editor = editor
    else
      raise TypeError, "Expected editor to be a valid editor key, a format string or a callable."
    end
  end
end

+ (Object) use_pry!

Enables experimental Pry support in the inline REPL

If you encounter problems while using Pry, please file a bug report at https://github.com/charliesome/better_errors/issues



111
112
113
# File 'lib/better_errors.rb', line 111

def self.use_pry!
  REPL::PROVIDERS.unshift const: :Pry, impl: "better_errors/repl/pry"
end