Skip to content

Generalize Must for any value - #109

Merged
korya merged 1 commit into
masterfrom
korya-api-generic-must
Aug 31, 2026
Merged

Generalize Must for any value#109
korya merged 1 commit into
masterfrom
korya-api-generic-must

Conversation

@korya

@korya korya commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Problem

ha.Must only 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 the ha.Assertion interface.

Solution

Make ha.Must generic so it unwraps any (T, error) constructor without changing its panic-on-error contract.

Before:

assertion := ha.Must(ha.AssertJQ(`.status == "healthy"`))
// http.NewRequest cannot be passed to ha.Must.

After:

request := ha.Must(http.NewRequest(http.MethodGet, url, nil))
assertion := ha.Must(ha.AssertJQ(`.status == "healthy"`))

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 as ha.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

  • Update the README library sample to construct the request inline.
  • Add tests and an executable example covering both assertions and HTTP requests; both helper branches are covered.
  • Record the generalized API in the unreleased changelog.

Related:

🤖 Generated with Claude Code

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>
@korya
korya marked this pull request as ready for review August 31, 2026 01:14
@korya
korya merged commit 1561062 into master Aug 31, 2026
8 checks passed
@korya
korya deleted the korya-api-generic-must branch August 31, 2026 01:14
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.

1 participant