Generalize Must for any value - #109
Merged
Merged
Conversation
Previously, Must only unwrapped assertion constructors. Make it generic so callers can also inline standard Go constructors such as http.NewRequest while retaining the same panic-on-error contract for programmer-owned input. Co-Authored-By: OpenAI Codex (GPT-5) <noreply@openai.com>
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.
Problem
ha.Mustonly unwraps assertion constructors, so Go consumers cannot use the same concise error contract with other constructors.The restriction is artificial: its behavior depends only on an
(value, error)pair, not on theha.Assertioninterface.Solution
Make
ha.Mustgeneric so it unwraps any(T, error)constructor without changing its panic-on-error contract.Before:
After:
Existing assertion calls compile unchanged. Generic inference requires a typed value, so the uncommon
ha.Must(nil, err)form must specify its intended type, such asha.Must[*http.Request](nil, err).The helper remains intended for static, programmer-owned input. Constructors fed by untrusted runtime input should return their errors normally instead of converting them into panics.
No visual change: this is a Go API and documentation update.
Other Changes
Related:
🤖 Generated with Claude Code