When should I use Result vs panic! for invalid server requests?

After reading this thread and the other recent thread(s) about panics I re-re-read the panic macro docs and see this
This macro should be used to avoid proceeding using incorrect values, such as from external sources.
and I think that could be understood as saying use a panic for an invalid server request.

That same doc panic in std - Rust also says, immediately before that statement:

Result enum is often a better solution for recovering from errors than using the panic! macro.

I think that could be understood as saying Result is a better way to handle invalid server requests.

I would interpret "external sources" as something far more serious, like a hardware register that is not in the correct state. Or some nonsense returned from calling a C function.

Clearly statement is just a heads up that there is a thing called Result rather than any suggested rule about when to use either.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.