5 ms·
I arrived to a similar conclusion. I come from Java and in Java you have exceptions with TryCatch clauses and declaring them in function signatures. It works fa
by tzahifadida 2y ago
I arrived to a similar conclusion. I come from Java and in Java you have exceptions with TryCatch clauses and declaring them in function signatures. It works fairly well but very difficult and not idiomatic to Golang.
Therefor, I created a simple rule. If you do not know what this error means to the user yet then let it stay a fmt.errorf("xx:%w",err). If you do, wrap it in your own custom ServerError struct and return that type from now on. Do not change the meaning of ServerError even if you wrap the Error with another ServerError.
- RVuRnvbM2e 2y agoIt is telling that you come from Java with this opinion. OP's approach is certainly not idiomatic Go.
- wruza 2y agoIdiomatic here means no idiom suggested really. So yeah, non-idiomatic.