Repository navigation
feat: debug mode records a response holding an unknown enum value - #80
Merged
Merged
Conversation
A value of an enum the specification does not list decodes, so debug mode never recorded it. In debug mode, each type that holds an enum, through its members, lists, maps, pointers and union alternatives, gets an unknownEnum method, and the client records the call when what it decoded holds a value its enum's Valid rejects. An optional member left out, at its zero value, is no unknown value. Outside debug mode, nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
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.
A value of an enum that the specification does not list still decodes, since an enum is a plain string or number, so debug mode never recorded it. Now it does.
How: rather than writing out a
v.Foo != nil && v.Foo.Bar != nil && !v.Foo.Bar.MyEnum.Valid()chain at each call site, debug mode gives each type that holds an enum anunknownEnummethod, which reaches every enum the type holds:ia != nil, i.e. when the client is in debug mode at runtime, and records the call once withc.keep. Clients not generated with-debugdon't change at all: no method and no check. The non-debug golden files are untouched.Tests
TestDebug_UnknownEnumchecks that each unknown value is recorded with its response, and that known values or a missing optional one are not.TestEnumsCheckcovers nested shapes the specs don't reach: map keys, a pointer to a slice, nested lists, type aliases, and a self-referencing type with no enum.unknownEnummethods compile.The debug mode section of the README now mentions this.
Generated by Claude Code