The Crystal Programming Language Forum

Consider silencing irrelevant lines in stack trace in console

Sometimes stack trace has lots of irrelevant lines in error messages in console.

In example below I made mistake, notice how the relevant lines get lost in the huge stack trace:

alex$ crystal play.cr 
Unhandled exception: expecting int or float but was Null at 1:6 (JSON::ParseException)
  from /apps/crystal-0.32.0-1/src/json/pull_parser.cr:555:5 in 'parse_exception'
  from /apps/crystal-0.32.0-1/src/json/pull_parser.cr:155:7 in 'read_float'
  from /apps/crystal-0.32.0-1/src/json/from_json.cr:110:5 in 'new'
  from /apps/crystal-0.32.0-1/src/json/from_json.cr:136:11 in 'new'
  from /apps/crystal-0.32.0-1/src/json/from_json.cr:13:3 in 'from_json'
  from lib/helpers.cr:7:5 in 'load'
  from play.cr:5:1 in '__crystal_main'
  from /apps/crystal-0.32.0-1/src/crystal/main.cr:97:5 in 'main_user_code'
  from /apps/crystal-0.32.0-1/src/crystal/main.cr:86:7 in 'main'
  from /apps/crystal-0.32.0-1/src/crystal/main.cr:106:3 in 'main'

The relevant part is this:

alex$ crystal play.cr 
Unhandled exception: expecting int or float but was Null at 1:6 (JSON::ParseException)
  from lib/helpers.cr:7:5 in 'load'
  from play.cr:5:1 in '__crystal_main'

Proposal:

Color stack trace lines that belong to crystal core with gray colour. The error message would still contain the full information and it will be easier to focus on the relevant part.

Alternative solution would be to highlight those two lines, but silencing irrelevant part with grey color seems preferable as it would keep the console more quiet.

The core developers that need those lines could set flag that disables that mode on their machines.

1 Like

Somewhat related: Better runtime backtraces

I could definitely see some compile time flag or other to be either “friendly” or “non friendly” backtraces or something, similar to the compiler with its . The main.cr stuff I’ve wondered before if maybe it should just always be excluded…like universally…

it’s not a huge deal today because after you’ve used it long enough your create a mental filter so you just skip over the stdlib lines :slight_smile:

It’s not nice to force human to do a machine’s job :slight_smile:

1 Like

In this situation, it’s not the compiler issue, more of the best practice and your desire tool is a code/static checker for vetting bad written code and advice you to fix it.

There’s definitely room for improvement, PR’s welcome! :)