Remix.run Logo
lionkor 2 hours ago

> Rust lacks a uniform error type

Rust has practically one error, it's the Error trait. The things you've listed are some common ways to use it, but you're entirely fine with just Box<dyn Error> (which is basically what anyhow::Error is) and similar.

fweimer 2 hours ago | parent | next [-]

Surely you need an alternative to Box<dyn Error> for reporting memory allocation failures?!

dwattttt an hour ago | parent [-]

A &(dyn Error + 'static) should be fine for that; you don't need any allocated/variable sized data in a memory allocation failure.

BobbyJo 2 hours ago | parent | prev [-]

Having many semantic options for error usage is functionally the same as having many error types, except worse.

ViewTrick1002 2 hours ago | parent [-]

They all convert seamlessly, and the enums make the branches explicit. Don't even need to check the documentation to find which errors supposedly exists like in Go with its errors.Is, errors.As, wrapping and what not.

An easy rule before you make a knowledge based choice is Thiserror for libraries, helping you create the standard library error types and Anyhow for applications, easy strings you bubble up.

Or just go with anyhow until you find a need for something else.

https://crates.io/crates/anyhow

https://crates.io/crates/thiserror