I defer these AND check the errors. https://pkg.go.dev/go.uber.org/multierr#hdr-Deferred_Functio... has a nice API. I wrote my own version for $WORK package (as our policy is that all errors must be wrapped with a message), used like: func foo() (retErr error) { x := thing.Open(name) defer errors.Close(&retErr, x, "close thing %v", name) ... } You can steal the code from here: https://github.com/pachyderm/pachyderm/b…
Like this?
switch {
case strings.Contains(err.Error(), "close thing foo"):
// deal with foo close error
case strings.Contains(err.Error(), "close thing bar"):
// deal with bar close error
}
And if so, what lead you or your organization to prefer "stringly-typed" errors over the idiomatic approach?