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

Check if EncodeLevel is set to avoid nil pointer dereference #1058

Merged

Conversation

aerosol
Copy link
Contributor

@aerosol aerosol commented Feb 4, 2022

Hello,

Apologies in advance, this is my first go PR.

This PR checks if EncodeLevel is set before calling it on final encoder clone. This prevents panic on nil pointer dereference in case it hasn't been supplied by the user. For an untrained eye, the stacktrace wasn't making it super clear that EncodeLevel must be provided along with LevelKey, so hopefully an explicit check hints at it for someone reading the source code.

I wasn't sure if maybe providing a sensible default here would've been better, but looking at the console logger, a similar check is made.

Thanks.

@CLAassistant
Copy link

CLAassistant commented Feb 4, 2022

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Feb 4, 2022

Codecov Report

Merging #1058 (c2a7c3a) into master (a1155d9) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1058   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files          48       48           
  Lines        2111     2111           
=======================================
  Hits         2075     2075           
  Misses         28       28           
  Partials        8        8           
Impacted Files Coverage Δ
zapcore/json_encoder.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1155d9...c2a7c3a. Read the comment docs.

Copy link
Collaborator

@abhinav abhinav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@abhinav abhinav merged commit a7613b2 into uber-go:master Feb 4, 2022
@aerosol aerosol deleted the fix/dont-crash-on-encodelevel-missing branch February 4, 2022 22:05
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.

None yet

3 participants