https://github.com/yegor256/backtrace
Ruby gem to print exception backtrace nicely
https://github.com/yegor256/backtrace
backtrace exceptions ruby ruby-gem
Last synced: 11 months ago
JSON representation
Ruby gem to print exception backtrace nicely
- Host: GitHub
- URL: https://github.com/yegor256/backtrace
- Owner: yegor256
- License: mit
- Created: 2018-10-12T11:48:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-23T05:32:32.000Z (almost 2 years ago)
- Last Synced: 2024-05-23T06:33:36.276Z (almost 2 years ago)
- Topics: backtrace, exceptions, ruby, ruby-gem
- Language: Ruby
- Homepage: https://rubygems.org/gems/backtrace
- Size: 218 KB
- Stars: 15
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README

[](http://www.rultor.com/p/yegor256/backtrace)
[](https://www.jetbrains.com/ruby/)
[](https://github.com/yegor256/backtrace/actions/workflows/rake.yml)
[](http://badge.fury.io/rb/backtrace)
[](https://codeclimate.com/github/yegor256/backtrace/maintainability)
[](http://rubydoc.info/github/yegor256/backtrace/master/frames)
[](https://hitsofcode.com/view/github/yegor256/backtrace)
[](https://github.com/yegor256/backtrace/blob/master/LICENSE.txt)
A Ruby backtrace nicely printed.
First, install it:
```bash
$ gem install backtrace
```
Then, use it like this, to print a backtrace:
```ruby
require 'backtrace'
begin
# do something dangerous
rescue StandardError => e
puts Backtrace.new(e)
end
```

A more compact version would use a block:
```ruby
require 'backtrace'
Backtrace.exec(swallow: true) do
# do something dangerous
end
```
You can also provide a logging facility, to log the backtrace:
```ruby
require 'backtrace'
log = Log.new # it must implement method error(msg)
Backtrace.exec(swallow: true, log: log) do
# do something dangerous
end
```
Sometimes you may need to hide unimportant lines of the backtrace,
which are not related to your code base. You can use `mine` argument
of the constructor, which is a regular expression or a string. When it's met
in the backtrace, the printing will stop:
```ruby
require 'backtrace'
begin
# do something dangerous
rescue StandardError => e
puts Backtrace.new(e, mine: 'yegor')
end
```
That's it.
## How to contribute
Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
Make sure your build is green before you contribute
your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
[Bundler](https://bundler.io/) installed. Then:
```
$ bundle update
$ bundle exec rake
```
If it's clean and you don't see any error messages, submit your pull request.