Git Product home page Git Product logo

backtrace_always's Introduction

BacktraceAlways

Build Status

Always print the message, class, and backtrace when an exception is raised

Overview

require "backtrace_always"

def foo
  bar
end

def bar
  baz
end

def baz
  begin
	raise "some error brah brah"
  rescue => e
	puts "caught: #{e}"
  end
end

BacktraceAlways.enable!

foo  # backtrace to $stderr

BacktraceAlways.disable!

foo  # no backtrace to $stderr

BacktraceAlways { foo }  # within the block, backtrace to $stderr

BacktraceAlways.enable_inspect!

def div(n)
  10/n
end

begin
  div(0)
rescue => e
  p e  # prints the backtrace
end

BacktraceAlways.disable_inspect!

io = File.open("out.log", "w")
BacktraceAlways.output = io
BacktraceAlways { foo } # backtrace to io
io.close

BacktraceAlways.output = logger  # Will log at debug level

Installation

Bundler

gem "backtrace_always"

RubyGems

gem install backtrace_always

Backtrace Printing

If TracePoint is available (Ruby >= 2 in most cases) all exceptions will have their backtrace printed (yes, even Exception sub classes).

If TracePoint is not available raise is overridden, and only explicit calls to it will print the backtrace. In this case exceptions raised by the Ruby interpreter will not have their backtrace printed.

By default BacktraceAlways acts like warn and will output to $stderr only if warnings are enabled. This can be changed by setting BacktraceAlways.output to the IO instance of your choosing.

Why?

To ease the pain of tracking down bugs in bad codebases.

Author

Skye Shaw [skye.shaw {AT} gmail.com]

License

Copyright (c) 2015 Skye Shaw. Released under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.