Repository navigation
chore(lint): enable nilerr in golangci-lint - #1776
Conversation
|
Hey @mbrandenburger 👋 thanks for the PR! This comment updates automatically as you push changes -- think of it as your PR's live scoreboard! PR Checks✅ DCO Sign-off -- All commits have valid sign-offs. Nice work! ❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:
You'll need to sign your commits with GPG (e.g. ✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing! ❌ Issue Link -- This PR is not linked to any issue. Please reference an issue using a closing keyword (e.g. ⏳ All checks must pass before this PR can be reviewed. You've got this! |
|
Tick the box to add this pull request to the merge queue (same as
|
Enables nilerr, which flags `if err != nil { return nil }`. It reported
5 findings: 3 real bugs fixed, 2 deliberate swallows (each now logged).
One of the two also carries //nolint:nilerr; the other needs none, because
logging err in the block is enough for nilerr to stop reporting. No
deferrals.
- platform/fabric/sdk/dig/sdk.go:175 - real bug: a config lookup error
for the default network's driver was conflated with a driver-name
mismatch and silently ignored (and would have nil-pointer-dereferenced
on c.Driver had the error path ever fired). Split the error check out
and return it wrapped with errors.Wrapf.
- platform/fabricx/core/vault/vault.go:436 - real bug: a genuine
queryService.GetState RPC/network error was conflated with "no
committed value" and silently swallowed. Split it out and return it
wrapped with errors.Wrapf.
- platform/fabricx/core/vault/vault.go:441 - deliberate: mds.GetFieldMapping
is documented to return an error on both a genuine failure and an
ordinary miss (see its comment in
platform/fabric/core/generic/transaction/services.go), so callers
must treat any error as "no mapping". Documented that reasoning in a
prose comment at the call site and added a debug log line (there was
none before). No //nolint is needed here: logging err in the block is
enough for nilerr to stop reporting.
- platform/view/services/config/config_util.go:58 - real bug:
byteSizeDecodeHook already returns a hard "overflows uint32" error a
few lines below for a related overflow case; the ParseUint failure a
few lines above (uint64 overflow before the shift) was silently
deferred to the default decoder instead of being reported the same
way. Now returns the error wrapped with errors.Wrapf.
- integration/fabric/events/views/events.go:49 - deliberate: this test
callback captures event.Err into the outer eventError variable for
the test's own assertions; the callback's own error return only
triggers a log line in the listener goroutine (RegisterChaincodeEvents)
and has no bearing on the test outcome. Added a debug log line for the
error (there was none) and //nolint:nilerr with that reasoning.
Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
431cd27 to
42d9a37
Compare
nilerrflagsif err != nil { return nil }— checking an error but returningnil(or another nil-valued error) instead of propagating it.Part of #1755.
Scoping
Five findings: three real bugs fixed, two deliberate swallows (each now logged, one also carrying
//nolint:nilerr).platform/fabric/sdk/dig/sdk.go:175— real bug: a config-lookup error for the default network's driver was conflated with a driver-name mismatch and silently ignored, which would have nil-pointer-dereferenced onc.Driverhad the error path ever fired. Split the error check out and return it wrapped witherrors.Wrapf.platform/fabricx/core/vault/vault.go:436— real bug: a genuinequeryService.GetStateRPC/network error was conflated with "no committed value" and silently swallowed. Split it out and return it wrapped witherrors.Wrapf.platform/fabricx/core/vault/vault.go:441— deliberate:mds.GetFieldMappingis documented to return an error on both a genuine failure and an ordinary miss (see its comment inplatform/fabric/core/generic/transaction/services.go), so callers must treat any error as "no mapping". Documented that reasoning in a comment at the call site and added a debug log line that wasn't there before — loggingerrin the block is enough fornilerrto stop reporting, so no//nolintis needed here.platform/view/services/config/config_util.go:58— real bug:byteSizeDecodeHookalready returns a hard "overflows uint32" error a few lines below for a related overflow case; theParseUintfailure a few lines above (uint64 overflow before the shift) was silently deferred to the default decoder instead of being reported the same way. Now returns the error wrapped witherrors.Wrapf.integration/fabric/events/views/events.go:49— deliberate: this test callback capturesevent.Errinto the outereventErrorvariable for the test's own assertions; the callback's own error return only triggers a log line in the listener goroutine (RegisterChaincodeEvents) and has no bearing on the test outcome. Added a debug log line for the error and//nolint:nilerrwith that reasoning.Verification
make checksexits 0 across all four modules.Note for reviewers
This branch is independent — rooted directly on current
main, not stacked on any other wave-3 PR. It should merge cleanly regardless of the order the other wave-3 PRs land in.