top | item 42448478

(no title)

tzahifadida | 1 year 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.

discuss

order

RVuRnvbM2e|1 year ago

It is telling that you come from Java with this opinion. OP's approach is certainly not idiomatic Go.

wruza|1 year ago

Idiomatic here means no idiom suggested really. So yeah, non-idiomatic.