3 ms·
It would be still nice do "return if error" in one line say via some "macro" (I'd kill for Rust-like macros in go...) err!(err,"Connection to %s failed",se
by ilyt 4y ago
It would be still nice do "return if error" in one line say via some "macro" (I'd kill for Rust-like macros in go...)
err!(err,"Connection to %s failed",serverAddr")
or even
return ErrConnFailed{address,err} if err != nil
instead of
if err != nil {
return "",nil,Struct{},fmt.Errorf("Connection to %s failed: %s",serverAddr,err)
}
You can't even shorten it to one line because go fmt will "helpfully" expand it back to 3 lines...
I do think writing context (whether by error type or "just" text) with each error is the way to go vs "just throw it up the stack and hope for best" but Go syntax fails it in that quest.