not swallowed levels of the backtrace on unrescued exception

Discussion in 'Ruby' started by Roger Pack, Feb 7, 2009.

  1. Roger Pack

    Roger Pack Guest

    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
    --
    Posted via http://www.ruby-forum.com/.
     
    Roger Pack, Feb 7, 2009
    #1
    1. Advertising

  2. Roger Pack

    Ken Bloom Guest

    On Sat, 07 Feb 2009 10:51:23 -0500, Roger Pack 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

    --
    Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
    Department of Computer Science. Illinois Institute of Technology.
    http://www.iit.edu/~kbloom1/
     
    Ken Bloom, Feb 8, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ferenc Engard

    exception backtrace for ruby/tk programs

    Ferenc Engard, Oct 9, 2003, in forum: Ruby
    Replies:
    2
    Views:
    143
    Hidetoshi NAGAI
    Oct 16, 2003
  2. Joel VanderWerf
    Replies:
    0
    Views:
    98
    Joel VanderWerf
    Nov 28, 2003
  3. Brian Takita

    Hiding backtrace with "x levels"

    Brian Takita, Nov 11, 2007, in forum: Ruby
    Replies:
    9
    Views:
    133
    Alex Chaffee
    Dec 5, 2007
  4. Victor 'Zverok' Shepelev

    Get rid of "... XX levels..." in error backtrace

    Victor 'Zverok' Shepelev, May 5, 2008, in forum: Ruby
    Replies:
    1
    Views:
    103
    Justin Collins
    May 6, 2008
  5. Pavils Jurjans

    onmouseout events are swallowed

    Pavils Jurjans, Mar 5, 2004, in forum: Javascript
    Replies:
    1
    Views:
    93
Loading...

Share This Page