3 ms·
The problem here is that if your style is not to return the error, but wrap it, you need a way to wrap it. You could use special syntax x != x() ~ "x faile
by KingOfCoders 2y ago
The problem here is that if your style is not to return the error, but wrap it, you need a way to wrap it.
You could use special syntax
x != x() ~ "x failed"
that would wrap the error and return it,
x, err := x()
if err != nil {
return fmt.Errorf("x failed: %w", err)
}
is more verbose but less so compared to the "just return error" case.
If you want to get rid of that, you need to have some auto conversion magic. This the way Rust does it, but it adds magic, you can't see the error handling, Rust needs (slow compiling) macros for this etc.