From: mame@... Date: 2020-04-21T09:36:03+00:00 Subject: [ruby-core:98000] [CommonRuby Feature#8661] Add option to print backstrace in reverse order(stack frames first & error last) Issue #8661 has been updated by mame (Yusuke Endoh). I've created a PR for `--suppress-backtrace=num` option. https://github.com/ruby/ruby/pull/3047 @matz Could you confirm if the behavior is right as you think? t.rb ```ruby def f1 = raise def f2 = f1 def f3 = f2 def f4 = f3 def f5 = f4 def f6 = f5 def f7 = f6 def f8 = f7 def f9 = f8 f9 ``` `--suppress-backtrace=3` limits the backtrace up to three lines, so the rest seven lines are omitted. ``` $ ./miniruby --suppress-backtrace=3 t.rb t.rb:1:in `f1': unhandled exception from t.rb:2:in `f2' from t.rb:3:in `f3' from t.rb:4:in `f4' ... 7 levels... ``` `--suppress-backtrace=8` limits it up to eight, even if the lines being omitted are only two lines. ``` $ ./miniruby --suppress-backtrace=8 t.rb t.rb:1:in `f1': unhandled exception from t.rb:2:in `f2' from t.rb:3:in `f3' from t.rb:4:in `f4' from t.rb:5:in `f5' from t.rb:6:in `f6' from t.rb:7:in `f7' from t.rb:8:in `f8' from t.rb:9:in `f9' ... 2 levels... ``` If the line being omitted is only one, no lines are omitted. ``` $ ./miniruby --suppress-backtrace=9 t.rb t.rb:1:in `f1': unhandled exception from t.rb:2:in `f2' from t.rb:3:in `f3' from t.rb:4:in `f4' from t.rb:5:in `f5' from t.rb:6:in `f6' from t.rb:7:in `f7' from t.rb:8:in `f8' from t.rb:9:in `f9' from t.rb:10:in `
' ``` `--suppress-backtrace=1` shows only the first level (except the message line). ``` $ ./miniruby --suppress-backtrace=1 t.rb t.rb:1:in `f1': unhandled exception from t.rb:2:in `f2' ... 9 levels... ``` `--suppress-backtrace=0` omits all backtrace except the message line. ``` $ ./miniruby --suppress-backtrace=0 t.rb t.rb:1:in `f1': unhandled exception ... 10 levels... ``` ---------------------------------------- Feature #8661: Add option to print backstrace in reverse order(stack frames first & error last) https://bugs.ruby-lang.org/issues/8661#change-85229 * Author: gary4gar (Gaurish Sharma) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- Currently the way ruby prints the backtrace is that the error comes first & then the stack frames. like this ``` Main Error Message stack frame 1 stack frame 2 stack frame 3 ..... ``` this is perfectly fine provided 1. Backstraces are short, so fits in terminal.hence, no need to scroll. 2. you read it from top to bottom. But, I am a rails developer where 1. Backstraces are always HUGE, therefore seldom don't fit in terminal. Means LOTS of scrolling to do everytime we get an error. 2. in terminal we tend to read backstraces from bottom to top, especially when tailing(tail -f) the production logs. 3. people, who practice Test-driven development literally spend most of their time scrolling to read backstraces to the point most end up buying a larger display. Proposed Solution: Please add a way so we can configure backstraces to be printed in reverse order. so if you are reading from bottom, say from terminal, you can get the main error message without need to scroll. like this ``` stack frame 3 stack frame 2 stack frame 1 Main Error Message ..... ``` this would save lot of time because when the error message is print at the bottom, no need to scroll for reading it. Not sure if this can be done today. I tried Overriding Exception#backtrace but it caused stack level too deep & illegal hardware instruction Error. Attached are currently what backstrace currently looks like & how there be an option to make it look for comparison. ---Files-------------------------------- current.log (5.13 KB) proposed.log (4.9 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: