Hacker News new | ask | show | jobs
by tzahifadida 541 days 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.

1 comments

It is telling that you come from Java with this opinion. OP's approach is certainly not idiomatic Go.
Idiomatic here means no idiom suggested really. So yeah, non-idiomatic.