Disable stack trace display in Rails console

Is there a way to reduce the frequency of error messages in the rails console? In particular, turn off stack trace display? This is useless most of the time, and completely annoying when I suffer from a case with stupid fingers.

When I type something like:

MyModel.vtrsyr

I don't need a stack trace to tell me that there is no "vtrsyr" method

+4
source share
1 answer

The important thing is that the rails console uses irb and has access to a range of irb configuration options.

$ rails c
Loading development environment (Rails 4.2.0)
>> conf
=> conf.ap_name="irb"
conf.auto_indent_mode=false
conf.back_trace_limit=16
.
.
.

And here it is: conf.back_trace_limit. So:

conf.back_trace_limit = 0

will effectively disable backtracking for the current session, and the output will be nice and concise:

>> MyModel.gnu
NoMethodError: undefined method `gnu' for MyModel:Class

or

>> obj.do_defective_math
ZeroDivisionError: divided by 0

, ~/.irbrc. - :

def toggle_trace
  if conf.back_trace_limit > 0
    conf.back_trace_limit = 0
  else
    conf.back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
  end
end

,

+6

Source: https://habr.com/ru/post/1618658/


All Articles