-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
*: Added errcheck and fixed not check errors [PART1]. #389
Conversation
cmd/thanos/sidecar_test.go
Outdated
@@ -23,12 +24,12 @@ global: | |||
testutil.Ok(t, err) | |||
|
|||
testutil.Ok(t, p.Start()) | |||
defer p.Stop() | |||
defer func() { _ = p.Stop() }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of interest why this change? Is it due to error check needing to assign the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, errcheck requires explicit return to make sure we don't forget about someting. I think it makes sense. Let's use testutil.Ok
here actually maybe (:
pkg/runutil/runutil.go
Outdated
} | ||
|
||
// There is already error, let's log this one. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - whitesapce
@@ -363,33 +364,33 @@ func Repair(dir string, id ulid.ULID, source SourceType, ignoreChkFns ...ignoreF | |||
if err != nil { | |||
return resid, errors.Wrap(err, "open block") | |||
} | |||
defer b.Close() | |||
defer runutil.BestEffortErr(nil, &err, b, "repair block reader") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you choose between BestEffortErr
and LogOnErr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore - I read the code again 😄
pkg/runutil/runutil.go
Outdated
logger = log.NewLogfmtLogger(os.Stderr) | ||
} | ||
|
||
level.Warn(logger).Log("msg", "detected best effort error", "err", errors.Wrap(err, fmt.Sprintf(wrap, a...))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This msg
makes me think of the BestEffortErr
func rather than LogOnErr
... maybe LogOnErr error closing
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ... only small nits and slight confusion msg logged in runutil
Due to high number of these issues, let's split the PR. Signed-off-by: Bartek Plotka <[email protected]>
Due to a high number of these issues, let's split the PR.
Thanks @asbjxrn for finding some not checked errors. This motivates us to fix all of these places. Some of them are serious, some not, but I think it is better to check all errors 100% time. (:
Signed-off-by: Bartek Plotka [email protected]
Changes
runutil
helpers for closing functions.Verification
CI, errcheck