Description
A big improvement to the speed at which I can find the origin of a panic would be to reverse the order of the stack trace. At the moment the last line of the stack trace is always main
. This means the stack trace is written deep->shallow, or in reverse(!) chronological order:
1: 0x10977219c - function_that_caused_the_panic
2: 0x1097738ee - foo
3: 0x109773590 - bar
4: 0x109773cf6 - baz
5: 0x109773b94 - badger
6: 0x109757669 - main
What you are generally looking for is the place that caused the panic (e.g. the line with an assert!
or panic!
on it), and so I think it would make sense to have that line last so that it is easy to find. This is particularly important when the call stack is deep and it fills your terminal. Here is a more in-depth argument for this.
So my suggestion is: reverse the stack trace to print the stack frames in chronological order, shallow->deep, with main
on the top and the stack frame with the panic at the end:
6: 0x109757669 - main
5: 0x109773b94 - badger
4: 0x109773cf6 - baz
3: 0x109773590 - bar
2: 0x1097738ee - foo
1: 0x10977219c - function_that_caused_the_panic
I realize this can become quite the bikeshedding religious war, and maybe this has been discussed before – if so, I apologize. Still, until the blog post above brought it up I didn't realize that most languages – including Rust – was doing it wrong, and that there was a better way. In C++ I switched the order I print stack traces about a year ago, and since then it has saved me a lot of scrolling.
EDIT: I've created a forum thread about this here: https://users.rust-lang.org/t/reverse-stack-trace-order/8786