Right now some errors can be unwieldy to read for a few reasons
- It shows all frames. This can lead to pages of text that looks overwhelming and makes it hard to the error.
- It is not always clear what the error is or where it is located
The Proposed Changes
- By default, just show the code with the error, not the entire stack trace. This is what Elm does and it works quite well. Helps focus on what is necessary
- Add a command line option and/or ENV to show the full trace. Sometimes it is useful to see more, but let’s make that optional instead of making the current verbose output the default. Example ``
- Some changes to how the error is displayed to make it easier to scan at a glance. Code + pics attached
Example Code and Screenshots
For errors without more info (just one line)
- Prefix with “Error”
- Print error message in yellow and bold
- (not sure about this) show how to print the full trace (like it does now)
- Show what file it is
- Show line number right by the source code line
- Show code line (maybe bolded?)
More screenshots at https://github.com/paulcsmith/crystal-errors
For errors with more than one line
- Print first line in yellow just like other errors
- Everything after first newline goes after the source line.
- Print surrounding lines
- Only bold line with the problem
- Show the expanded code, and underneath it show the unexpanded code
It is important to show both. The unexpanded part show what the user wrote. The expanded part helps figure out why the issue might be there. Use --verbose/–debug for more in-depth look if it still is not enough
Not Sure About
- Not sure about including the dim line that says how to show full trace. Maybe not useful enough?
- Should source code line be bolded? Maybe too much is going on.
Who would do this work?
I wish I had more time for this, but with all the stuff with Lucky I just don’t have time. I’m happy to help where I can but I likely won’t be able to help with code.
I really want this feature though and will open up a Bounty Hunt to help out if this gets approved :D