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

Handle nil context value in field.FromContext() func #298

Merged
merged 4 commits into from
Sep 19, 2019
Merged

Conversation

SupriyaKasten
Copy link
Contributor

Change Overview

Handle nil context value in field.FromContext() func

Pull request type

Please check the type of change your PR introduces:

  • Work in Progress
  • Refactoring (no functional changes, no api changes)
  • Trivial/Minor
  • Bugfix
  • Feature
  • Documentation

@mergify mergify bot merged commit bd447e0 into master Sep 19, 2019
@tdmanv tdmanv deleted the field-context branch September 19, 2019 01:29
@@ -10,8 +10,10 @@ const ctxKey = contextKey(43)

// FromContext returns the fields present in ctx if any
func FromContext(ctx context.Context) Fields {
if s, ok := ctx.Value(ctxKey).(Fields); ok {
return s
if ctx != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

OTOH, this should be handled by the caller. For example, context.WithDeadline() does not accept a nil context.
However, this was not explicitly documented in FromContext from the beginning, and overall this approach is more robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants