I had some trouble debugging one issue, and I missed the stack trace I get in other languages. Now I'm thinking maybe for unexpected errors I should panic instead of returning an error, so I get this stack trace?
Or do you just make better logs and don't panic ever?
I should have said meaningful backtraces: showing the nested calls across threads. Since async is stackless, can you elaborate? Do you mean they work to give you a partial picture? Or are you referring to async-backtrace?
There is an open issue for async external backtraces (in debuggers), but that's to be expected.
prints a backtrace with the relevant parts looking like this:
5: playground::foo::{{closure}}
at ./src/main.rs:2:5
6: playground::bar::{{closure}}
at ./src/main.rs:6:11
7: playground::main::{{closure}}
at ./src/main.rs:11:11
The fact that async tasks are sometimes moved from one thread to another is irrelevant and does not break the backtraces.
From API design perspective, panics generally are for bugs. If the cause of the error is programmer writing the program incorrectly, then panic. Otherwise you should return a Result.
If you're just debugging a program locally then panic!("woop") is fine — equivalent of printf-debugging. Just don't forget to remove it before committing/publishing.
Another compromise could be to add debug_assert! to make functions fail loudly in dev, but still return Result in release mode. This could make sense for really rare/unexpected errors.
Assuming that you can investigate and ship fixes promptly -- which obviously you want for other reasons too -- you should let devs panic! for "I don't think that can happen". You want the increased developer velocity of not writing a bunch of irrelevant code, as well the less debt of a bunch of untested error-handling paths.
Then the dev who wrote the panic! gets the bug if the panic is actually hit, with priority related to the frequency and consistency at which it can be hit.
Generally, I will try to return a result over panicking in all cases. The only time I tend not to is when I literally don't know how I would proceed. The only case that comes to mind for me, in that, is when a Mutex is poisoned (which usually indicates that something has gone Seriously Wrong).