egonSchiele / contracts.ruby

Contracts for Ruby.
http://egonschiele.github.com/contracts.ruby
BSD 2-Clause "Simplified" License
1.44k stars 82 forks source link

Contracts messes up backtraces (stacktraces) #276

Open md-work opened 6 years ago

md-work commented 6 years ago

In general I'm very happy with Contracts and I don't want to miss it anymore. Nevertheless, there's one annoying problem. With Contracts in use backtraces (stacktraces) become quite messed up.

I know I can use the NO_CONTRACTS environment variable. But that's not always a practical solution, because I need to restart the application and reproduce whatever took me to the backtrace.


Example 1: Backtrace from Contract violation

/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts.rb:49:in `block in <class:Contract>'
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts.rb:155:in `call'
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts.rb:155:in `failure_callback'
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts/method_handler.rb:143:in `rescue in block in redefine_method'
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts/method_handler.rb:136:in `block in redefine_method'
/home/user/mycode/app.rb:42:in `some_method_b'
[...]

Example 2: An exception in a method guided by a Contract

/home/user/mycode/app.rb:23:in `raise'
/home/user/mycode/app.rb:23:in `some_method_a'
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts/method_reference.rb:43:in `send_to'
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts/call_with.rb:79:in `call_with'
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts/method_handler.rb:138:in `block in redefine_method'
/home/user/mycode/app.rb:42:in `some_method_b'
[...]

Could you please look for a way to clean the backtrace from all lines with internal Contracts code? E.g.: /usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts/method_handler.rb:138:in *`block in redefine_method'

If that's possible, an global option to enable/disable that backtrace cleaning would be wonderful.