Repository navigation
feat(functions): Add payload matching for thrown function errors. Also fixes a bug in typescript, where errors in function contracts didn't behave correctly - #1404
Merged
Conversation
Thrown errors from registered functions now carry a serialised `payload`, which can be matched in the contract with the new `payload` parameter on the throwing function interactions (alongside `errorClassName` and `message`). A `responseName` can also be given so verification trigger groups can identify the error response by a stable name. In Java, the exception is serialised with Jackson using a Throwable mixin that strips the standard properties (stack trace, cause, message, etc), so public getters on the exception become the payload and Jackson annotations can control it. The caller side exposes the payload via FunctionCompletedExceptionally.getPayload(). Documentation notes that payload matching should generally be a last resort in favour of explicit, distinct error types. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Registered functions that throw in Typescript now produce a function failure result (errorClassName, message, payload) instead of a boundary failure, so throwing interactions can be verified against Typescript implementations. The payload is the error's own enumerable properties, excluding name, message, stack and cause. On the caller side, the mock function throws a FunctionCompletedExceptionally (mirroring the Java DSL) carrying the errorClassName, message and example payload from the contract. Adds willCallThrowingFunction and willReceiveFunctionCallAndThrow convenience functions, tests for both contracts, and documentation examples. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…errorInternals` Renames the matcher parameter, contract property, DSL builders, FunctionCompletedExceptionally accessors (getErrorInternals() / .errorInternals), tests, contracts and documentation. Also gives the verification CustomException an httpCode property so the caller contract's errorInternals expectation (an HttpStatusCode matcher) verifies against it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…rror.ts Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…n to case-definition-dsl and the generated DSL classes Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Merged
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.
Summary
errorInternals, matchable via a newerrorInternalsparameter on the throwing function interactions (WillReceiveFunctionCallAndThrow,WillCallThrowingFunction, and the named-argument variants), alongsideerrorClassNameandmessage. AbsenterrorInternalsmeans "don't check", so existing contracts are unaffected.responseName(_case:matcher:uniqueName) to the thrown-error matcher, so verification trigger groups can key on a stable name rather than the auto-generated description of theerrorInternalsmatcher.Throwablemixin that dropsstackTrace/cause/suppressed/localizedMessage/message, so public getters on the exception form the error internals and Jackson annotations (@JsonIgnore,@JsonProperty) control it. Serialisation failures surface as a configuration error with guidance. Caller side exposesFunctionCompletedExceptionally.getErrorInternals().name/message/stack/cause. The mock function on the caller side throws a newFunctionCompletedExceptionally(mirroring Java) witherrorClassName,exceptionMessageanderrorInternals. NewwillCallThrowingFunction/willReceiveFunctionCallAndThrowconvenience functions.FunctionResultMatchercheck/strip/describe/validate handleerrorInternals; mock execution echoes the stripped internals to callers.Test plan
case-core-plugin-functionspec: new check/strip/describe errorInternals casesComplexExceptionround-trips through definition and verification on both contracts, assertinggetErrorInternals(); a caller-sideerrorInternalsexpectation using anHttpStatusCodematcher verifies against a real thrown exception; full gradle suite greenErrorWithInternalsround-trips through definition and verification on both jest function contracts (test:local8/8,test:local:verify38/38)nx affectedbuild + test across JS packages green; lint and format cleannx build case-documentationgreen; example snippets regenerated🤖 Generated with Claude Code