fix: implement nil-safe Context methods on typhon.Request#176
Merged
craigfe merged 3 commits intomonzo:masterfrom Jan 31, 2025
Merged
fix: implement nil-safe Context methods on typhon.Request#176craigfe merged 3 commits intomonzo:masterfrom
craigfe merged 3 commits intomonzo:masterfrom
Conversation
craigfe
commented
Jan 30, 2025
| strategy: | ||
| matrix: | ||
| go-version: [1.17.x, 1.18.x] | ||
| go-version: [1.19.x, 1.23.x] |
Member
Author
There was a problem hiding this comment.
Fly-by change: the minimum supported version in go.mod is already 1.19, and I've introduced a use of any that causes this library to fail to compile on 1.17.
Contributor
There was a problem hiding this comment.
I think there may be references to 1.17 and 1.18 elsewhere, breaking CI 🙈
Contributor
There was a problem hiding this comment.
Hmm, no. Not sure why CI is blocked on actions that no longer exist. 🤔
Contributor
|
I think we might need someone with repo permissions to fix branch protection rules. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While downstreaming a new
slogfeature to Monzo's internal monorepo, I discovered that the emptytyphon.Requestvalue panics when the variouscontext.Contextmethods are called on it:This happens because
typhon.Requestembedscontext.Context, and so the zero value oftyphon.Requesthas a typed nil context. This PR adds wrappers for thecontext.Contextmethods that behave likecontext.Background()on the emptytyphon.Requestvalue instead.This is arguably not a bug: users of the library are expected to use either
typhon.NewRequestortyphon.NewRawRequestto construct request values, these functions explicitly handle thenilcontext case, and the library makes no promises about the validity of the zero value.Either way, we already have unit tests in our internal monorepo that build
typhon.Requestvalues manually and with the currenttyphon.Requestimplementation those tests are unstable: introducing a new call to one of thecontext.Contextmethods in a library (as I did in monzo/slog#22), can indirectly cause consumers of that library to panic. It's not difficult to add wrapper methods that work correctly for the emptytyphon.Requestvalue, so that's exactly what this PR does.