astefanutti commented on pull request #2766:
URL: https://github.com/apache/camel-k/pull/2766#issuecomment-976270481
> > @lburgazzoli the closure pattern looks good.
> > To be honest, even the "plain procedural" approach looks good to me:
>
> I do agree on this point and I originally opted to use it, however there
is a subtle issue in this block:
>
> ```go
> if err = io.WriteString(f, "hello world"); err != nil {
> f.Close()
> return err
> }
> ```
>
> Is it correct to swallow any error that may be detected while closing the
file ? In my case I experimented with the `multierr` package to combine
multiple errors but that's also something that I'm not sure about.
The author of the blog post indicates that the _close_ error is ignored,
because the _write_ error takes precedence. I'm not sure how to interpret that,
but I guess most importantly, an error is returned, and the caller error
handling flow is triggered. Also `close` is called, whatever the result is, but
an error is still returned, providing details why the write fails. Trying to
combine details about the _write_ and _close_ errors is possible, but I'm not
sure that's worth the extra complexity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]