The Wayback Machine - https://web.archive.org/web/20220426201159/https://github.com/cosmos/cosmos-sdk/issues/11785
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report errors in Close() defer functions #11785

Open
4 tasks
robert-zaremba opened this issue Apr 26, 2022 · 1 comment
Open
4 tasks

Report errors in Close() defer functions #11785

robert-zaremba opened this issue Apr 26, 2022 · 1 comment
Labels
C:errors good first issue Type: Dev UX Type: QA

Comments

@robert-zaremba
Copy link
Collaborator

@robert-zaremba robert-zaremba commented Apr 26, 2022

Description

Very often we ignore errors, or omit them in a defer functions, eg:

defer file.Close()

Proposal

Create a wrapper function:

func logError(logger, f func() error) {
    if err := f(); err != nil {
        logger.Error(err)
    }
}
...

defer logError(ctx.Logger(), file.Close)

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@robert-zaremba robert-zaremba added Type: Dev UX Type: QA C:errors labels Apr 26, 2022
@alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Apr 26, 2022

ACK. Would be in favor of calling it LogDeferred

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:errors good first issue Type: Dev UX Type: QA
2 participants