# Not swallowed levels of the backtrace on unrescued exception

**URL:** <https://www.ruby-forum.com/t/not-swallowed-levels-of-the-backtrace-on-unrescued-exception/159727>\
**Category:** Ruby\
**Created:** [February 7, 2009, 4:52pm UTC](https://www.ruby-forum.com/t/not-swallowed-levels-of-the-backtrace-on-unrescued-exception/159727 "2009-02-07T16:52:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [February 7, 2009, 4:52pm UTC](https://www.ruby-forum.com/t/not-swallowed-levels-of-the-backtrace-on-unrescued-exception/159727/1 "2009-02-07T16:52:12Z")

</div>

Currently ruby [at least versions 1.8.6 and greater]  
swallows the “middle” of backtraces if the thrown error was  
“SystemStackError”:  
ex:

> cat bad.rb  
> def go  
> go2  
> end

def go2  
go  
end  
go

> ruby bad.rb  
> bad.rb:5:in `go2': stack level too deep (SystemStackError) from bad.rb:2:in`go’  
> from bad.rb:5:in `go2' from bad.rb:2:in`go’  
> from bad.rb:5:in `go2' from bad.rb:2:in`go’  
> from bad.rb:5:in `go2' from bad.rb:2:in`go’  
> from bad.rb:5:in `go2' ... 22112 levels... from bad.rb:2:in`go’  
> from bad.rb:5:in `go2' from bad.rb:2:in`go’  
> from bad.rb:8

However, this has the unfortunate side effect of preventinf useful parts  
of the backtrace from being displayed in certain other cases, here’s an  
example I ran into just recently:

C:/dev/ruby-benchmark-suite/rails/substruct/vendor/plugins/attachment\_fu\_fixtures/lib/attachment\_fu\_fixtures.rb:53:in  
`include?': stack level too deep (SystemStackError) from C:/dev/ruby-benchmark-suite/rails/substruct/vendor/plugins/attachment_fu_fixtures/lib/attachment_fu_fixtures.rb:53:in`attachment\_model?’  
from  
C:/dev/ruby-benchmark-suite/rails/substruct/vendor/plugins/attachment\_fu\_fixtures/lib/attachment\_fu\_fixtures.rb:10:in  
`insert_fixture_without_attachment' from C:/dev/ruby-benchmark-suite/rails/substruct/vendor/plugins/attachment_fu_fixtures/lib/attachment_fu_fixtures.rb:28:in`insert\_fixture’  
from  
C:/dev/ruby-benchmark-suite/rails/substruct/vendor/rails/activerecord/lib/active\_record/fixtures.rb:639:in  
`insert_fixtures' from C:/dev/ruby-benchmark-suite/rails/substruct/vendor/rails/activerecord/lib/active_record/fixtures.rb:576:in`each’  
from  
C:/dev/ruby-benchmark-suite/rails/substruct/vendor/rails/activerecord/lib/active\_record/fixtures.rb:576:in  
`insert_fixtures' from C:/dev/ruby-benchmark-suite/rails/substruct/vendor/rails/activerecord/lib/active_record/fixtures.rb:520:in`create\_fixtures’  
from  
C:/dev/ruby-benchmark-suite/rails/substruct/vendor/rails/activerecord/lib/active\_record/fixtures.rb:520:in  
`each' ... 24 levels... from c:/ruby18/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in`invoke’  
from ./substruct\_start\_and\_bootstrap\_if\_necessary.rb:15  
from bm\_substruct\_request\_root\_100x.rb:8:in `require’  
from bm\_substruct\_request\_root\_100x.rb:8

So my question is:  
What would be a better way to handle this in core [I want to submit a patch, but am unsure what would be better].  
some possibilities: if $VERBOSE is set then output all levels.  
Have it output “100 lines” of backtrace each time–probably enough.

Thoughts?  
-=r

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [February 8, 2009, 7:41pm UTC](https://www.ruby-forum.com/t/not-swallowed-levels-of-the-backtrace-on-unrescued-exception/159727/2 "2009-02-08T19:41:02Z")

</div>

On Sat, 07 Feb 2009 10:51:23 -0500, Roger P. wrote:

> def go  
> go2  
> end
> 
> def go2  
> go  
> end  
> go

def go  
go2  
end

def go2  
go  
end

begin  
go  
rescue StandardError =\> e  
require ‘pp’  
pp e.backtrace  
end

will print all the levels, so what you should probably do is submit a  
patch to Rails or Rake to explicitly catch the exception and customize  
the output (possibly by grepping out things internal to rails and rake,  
or by printing more levels there.)

–Ken
