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

lint: Enable errcheck, fix failures #1345

Merged
merged 4 commits into from
Sep 6, 2023
Merged

Conversation

abhinav
Copy link
Collaborator

@abhinav abhinav commented Sep 1, 2023

This enables linting with errcheck on the repository.
Exclusions were added for functions that are known
to never fail, e.g. all Write methods on Zap's buffer.Buffer.

In attempting to enable exclusions for these functions,
I discovered and fixed a typo in the golangci.yml.

Complete list of issues fixed
encoder_test.go:44:18: Error return value is not checked (errcheck)
encoder_test.go:55:18: Error return value is not checked (errcheck)
error.go:64:19: Error return value of `arr.AppendObject` is not checked (errcheck)
http_handler.go:83:13: Error return value of `enc.Encode` is not checked (errcheck)
http_handler.go:88:14: Error return value of `enc.Encode` is not checked (errcheck)
http_handler.go:92:13: Error return value of `enc.Encode` is not checked (errcheck)
http_handler.go:95:13: Error return value of `enc.Encode` is not checked (errcheck)
http_handler_test.go:170:24: Error return value of `res.Body.Close` is not checked (errcheck)
logger.go:377:24: Error return value of `log.errorOutput.Sync` is not checked (errcheck)
sink.go:69:17: Error return value of `sr.RegisterSink` is not checked (errcheck)
stacktrace_ext_test.go:178:13: Error return value of `os.MkdirAll` is not checked (errcheck)
writer.go:65:11: Error return value of `c.Close` is not checked (errcheck)
writer_test.go:94:11: Error return value of `os.Remove` is not checked (errcheck)
writer_test.go:258:9: Error return value of `w.Write` is not checked (errcheck)
zapcore/buffered_write_syncer_bench_test.go:43:15: Error return value of `w.Stop` is not checked (errcheck)
zapcore/buffered_write_syncer_bench_test.go:47:12: Error return value of `w.Write` is not checked (errcheck)
zapcore/buffered_write_syncer_test.go:104:11: Error return value of `ws.Write` is not checked (errcheck)
zapcore/core.go:107:9: Error return value of `c.Sync` is not checked (errcheck)
zapcore/core_test.go:151:13: Error return value of `core.Write` is not checked (errcheck)
zapcore/encoder_test.go:288:17: Error return value of `enc.AddArray` is not checked (errcheck)
zapcore/encoder_test.go:316:17: Error return value of `enc.AddArray` is not checked (errcheck)
zapcore/encoder_test.go:723:14: Error return value of `mem.AddArray` is not checked (errcheck)
zapcore/entry.go:245:23: Error return value of `ce.ErrorOutput.Sync` is not checked (errcheck)
zapcore/entry.go:257:22: Error return value of `ce.ErrorOutput.Sync` is not checked (errcheck)
zapcore/error.go:101:19: Error return value of `arr.AppendObject` is not checked (errcheck)
zapcore/json_encoder_bench_test.go:34:16: Error return value of `enc.AddObject` is not checked (errcheck)
zapcore/json_encoder_bench_test.go:98:16: Error return value of `json.Marshal` is not checked (errcheck)
zapcore/json_encoder_impl_test.go:252:16: Error return value of `e.AddObject` is not checked (errcheck)
zapcore/json_encoder_impl_test.go:260:16: Error return value of `e.AddObject` is not checked (errcheck)
zapcore/json_encoder_impl_test.go:268:16: Error return value of `e.AddObject` is not checked (errcheck)
zapcore/json_encoder_impl_test.go:292:13: Error return value of `e.AddArray` is not checked (errcheck)
zapcore/json_encoder_impl_test.go:423:21: Error return value of `arr.AppendObject` is not checked (errcheck)
zapcore/json_encoder_impl_test.go:431:21: Error return value of `arr.AppendObject` is not checked (errcheck)
zapcore/json_encoder_impl_test.go:533:20: Error return value of `arr.AppendObject` is not checked (errcheck)
zapcore/level_test.go:162:16: Error return value of `l.MarshalText` is not checked (errcheck)
zapcore/memory_encoder_test.go:221:16: Error return value of `e.AddObject` is not checked (errcheck)
zapcore/memory_encoder_test.go:235:16: Error return value of `e.AddObject` is not checked (errcheck)
zapcore/memory_encoder_test.go:288:54: Error return value of `e.AppendReflected` is not checked (errcheck)
zapcore/memory_encoder_test.go:294:18: Error return value of `e.AppendArray` is not checked (errcheck)
zapcore/memory_encoder_test.go:305:18: Error return value of `e.AppendArray` is not checked (errcheck)
zapcore/memory_encoder_test.go:306:24: Error return value of `inner.AppendObject` is not checked (errcheck)
zapcore/memory_encoder_test.go:321:18: Error return value of `e.AppendArray` is not checked (errcheck)
zapcore/memory_encoder_test.go:322:24: Error return value of `inner.AppendObject` is not checked (errcheck)
zapcore/tee_test.go:123:13: Error return value of `tee.Write` is not checked (errcheck)
zapcore/write_syncer_bench_test.go:40:12: Error return value of `w.Write` is not checked (errcheck)
zapcore/write_syncer_bench_test.go:54:12: Error return value of `w.Write` is not checked (errcheck)
zapcore/write_syncer_bench_test.go:67:15: Error return value of `w.Stop` is not checked (errcheck)
zapcore/write_syncer_bench_test.go:71:12: Error return value of `w.Write` is not checked (errcheck)
zapcore/write_syncer_bench_test.go:86:12: Error return value of `w.Write` is not checked (errcheck)
zapcore/write_syncer_test.go:73:9: Error return value of `ws.Sync` is not checked (errcheck)
zaptest/observer/observer_test.go:176:15: Error return value of `logger.Write` is not checked (errcheck)

@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Merging #1345 (b86843b) into master (b900128) will increase coverage by 0.44%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1345      +/-   ##
==========================================
+ Coverage   97.58%   98.03%   +0.44%     
==========================================
  Files          52       52              
  Lines        3392     3403      +11     
==========================================
+ Hits         3310     3336      +26     
+ Misses         71       58      -13     
+ Partials       11        9       -2     
Files Changed Coverage Δ
error.go 100.00% <100.00%> (ø)
http_handler.go 100.00% <100.00%> (ø)
logger.go 96.55% <100.00%> (ø)
sink.go 100.00% <100.00%> (ø)
writer.go 100.00% <100.00%> (ø)
zapcore/core.go 93.61% <100.00%> (ø)
zapcore/entry.go 98.33% <100.00%> (+8.33%) ⬆️
zapcore/error.go 86.27% <100.00%> (+0.85%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

This enables linting with errcheck on the repository.
Exclusions were added for functions that are known
to never fail, e.g. all Write methods on Zap's buffer.Buffer.

In attempting to enable exclusions for these functions,
I discovered and fixed a typo in the golangci.yml.
Add a test for CheckedEntry re-use detection
that logs a message to ErrorOutput
when a CheckedEntry is accidentally reused.
@abhinav abhinav enabled auto-merge (squash) September 2, 2023 20:59
@abhinav abhinav merged commit 2b35963 into uber-go:master Sep 6, 2023
5 checks passed
@abhinav abhinav deleted the errcheck branch September 6, 2023 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants