• Stars
    star
    646
  • Rank 68,013 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pretty your exception backtrace.

PrettyBacktrace

Pretty your exception backtrace.

Installation

Add this line to your application's Gemfile:

gem 'pretty_backtrace'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pretty_backtrace

Usage

Use like that:

require 'pretty_backtrace'
PrettyBacktrace.enable

def recursive n
  str = "Hi #{n}!!  " * 128
  if n > 0
    recursive n - 1
  else
    raise "bottom of recursive"
  end
end

recursive 3

and you can see prettier backtrace (you can see local variable names and values).

test.rb:10:in `recursive' (n = 0, str = "Hi 0!!  Hi 0!!  Hi 0...): bottom of recursive (RuntimeError)
        from test.rb:9:in `recursive' (n = 1, str = "Hi 1!!  Hi 1!!  Hi 1...)
        from test.rb:9:in `recursive' (n = 2, str = "Hi 2!!  Hi 2!!  Hi 2...)
        from test.rb:9:in `recursive' (n = 3, str = "Hi 3!!  Hi 3!!  Hi 3...)
        from test.rb:15:in `<main>'

You only need to require "pretty_backtrace/enable" to eliminate "PrettyBacktrace.enable call".

PrettyBacktrace::CONFIG can change behaviour. See source code files for details.

Multi-line mode

You can use multi-line mode with the following configuration.

PrettyBacktrace.multi_line = true

Multi-line mode enable to show file contents and all variables (and pointing values) in each lines like that:

test.rb:11:in `recursive'
          [FILE]
             9|    recursive n - 1
            10|  else
        ->  11|    raise "bottom of recursive"
            12|  end
            13|end

          [LOCAL VARIABLES]
            n = 0
            str = "Hi 0!!  Hi 0!!  Hi 0!!  Hi 0!!  Hi 0!!  Hi 0!!  Hi 0!!  Hi 0...
: bottom of recursive (RuntimeError)
        from test.rb:9:in `recursive'
          [FILE]
             7|  str = "Hi #{n}!!  " * 128
             8|  if n > 0
        ->   9|    recursive n - 1
            10|  else
            11|    raise "bottom of recursive"

          [LOCAL VARIABLES]
            n = 1
            str = "Hi 1!!  Hi 1!!  Hi 1!!  Hi 1!!  Hi 1!!  Hi 1!!  Hi 1!!  Hi 1...

        from test.rb:9:in `recursive'
          [FILE]
             7|  str = "Hi #{n}!!  " * 128
             8|  if n > 0
        ->   9|    recursive n - 1
            10|  else
            11|    raise "bottom of recursive"

          [LOCAL VARIABLES]
            n = 2
            str = "Hi 2!!  Hi 2!!  Hi 2!!  Hi 2!!  Hi 2!!  Hi 2!!  Hi 2!!  Hi 2...

        from test.rb:9:in `recursive'
          [FILE]
             7|  str = "Hi #{n}!!  " * 128
             8|  if n > 0
        ->   9|    recursive n - 1
            10|  else
            11|    raise "bottom of recursive"

          [LOCAL VARIABLES]
            n = 3
            str = "Hi 3!!  Hi 3!!  Hi 3!!  Hi 3!!  Hi 3!!  Hi 3!!  Hi 3!!  Hi 3...

        from test.rb:15:in `<main>'

Contributing

There are no spec tests. I love to get your contributions!

  1. Fork it ( https://github.com/ko1/pretty_backtrace/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

More Repositories

1

rubyhackchallenge

Ruby
451
star
2

allocation_tracer

Add ObjectSpace::AllocationTracer module.
C
438
star
3

gc_tracer

Add GC::Tracer module.
C
308
star
4

yomikomu

Dump compiled iseq by binary (kakidasu) and load binary (yomidasu)
Ruby
179
star
5

nakayoshi_fork

Ruby
81
star
6

uc_ja

書籍『アンダースタンディング コンピュテーション』のサポートリポジトリです。
73
star
7

ractor-tvar

C
65
star
8

rspec-debug

Launch [debugger](https://github.com/ruby/debug) if spec is failed.
Ruby
35
star
9

rstfilter

Show Ruby script with execution results.
Ruby
34
star
10

kv

kv: A page viewer written in Ruby
Ruby
27
star
11

ruby-ptrace

ptrace wrapper for ruby
C
23
star
12

calleree

Calleree helps to analyze Ruby's caller-callee relationships.
C
18
star
13

vscode-ruby-rstfilter

Ruby's rstfilter extension
TypeScript
17
star
14

iseq_collector

iseq_collector gem
Ruby
16
star
15

prsnt

プレゼントを提供するためのウェブアプリケーション
Ruby
8
star
16

build-ruby

Build Ruby from source code.
Ruby
6
star
17

programming-elixir-1-6-ja

[プログラミングElixir(第2版)](https://www.ohmsha.co.jp/book/9784274226373/) サポートページ
6
star
18

simplepaste

SimplePaste web application
Ruby
5
star
19

finalize_block

This gem provide `finalize_block` method.
Ruby
4
star
20

many_examples

MaNy project examples
Ruby
3
star
21

ractor

to keep namespace
Ruby
3
star
22

ptask

Parallel task scheduler
C
2
star
23

tokyo11

Tokyo RubyKaigi 11
HTML
2
star
24

turtlefs

TurtleFS is Delay simulation file system using FUSE.
C
1
star
25

calcard

calcard
HTML
1
star
26

sample

1
star
27

ractor-lvar

Ractor::LVar
Ruby
1
star
28

pam_gh_user

1
star
29

mmapped_string

MmappedString
Ruby
1
star