Skip to content

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
TimothyJones merged 6 commits into
mainfrom
feat/function-error-payload
Aug 31, 2026
Merged

TimothyJones merged 6 commits into
mainfrom
feat/function-error-payload

Conversation

@TimothyJones

@TimothyJones TimothyJones commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Thrown errors from registered functions now carry their serialised content as errorInternals, matchable via a new errorInternals parameter on the throwing function interactions (WillReceiveFunctionCallAndThrow, WillCallThrowingFunction, and the named-argument variants), alongside errorClassName and message. Absent errorInternals means "don't check", so existing contracts are unaffected.
  • Adds an optional 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 the errorInternals matcher.
  • Java: exceptions are serialised with Jackson via a Throwable mixin that drops stackTrace/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 exposes FunctionCompletedExceptionally.getErrorInternals().
  • Typescript: registered functions that throw now produce a proper function failure result (previously a boundary failure, so throwing interactions couldn't be verified against TS implementations). The error internals are the error's own enumerable properties, excluding name/message/stack/cause. The mock function on the caller side throws a new FunctionCompletedExceptionally (mirroring Java) with errorClassName, exceptionMessage and errorInternals. New willCallThrowingFunction / willReceiveFunctionCallAndThrow convenience functions.
  • Core: FunctionResultMatcher check/strip/describe/validate handle errorInternals; mock execution echoes the stripped internals to callers.
  • Docs: new "Matching the content of an error" sections (TS + Java tabs) with a warning that matching on the error internals should generally be a last resort — prefer explicit, distinct error types.

Test plan

  • case-core-plugin-function spec: new check/strip/describe errorInternals cases
  • Java: ComplexException round-trips through definition and verification on both contracts, asserting getErrorInternals(); a caller-side errorInternals expectation using an HttpStatusCode matcher verifies against a real thrown exception; full gradle suite green
  • Typescript: ErrorWithInternals round-trips through definition and verification on both jest function contracts (test:local 8/8, test:local:verify 38/38)
  • nx affected build + test across JS packages green; lint and format clean
  • nx build case-documentation green; example snippets regenerated

🤖 Generated with Claude Code

TimothyJones and others added 3 commits August 31, 2026 02:14
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>
@TimothyJones TimothyJones changed the title feat(functions): Add payload matching for thrown function errors feat(functions): Add payload matching for thrown function errors. Also fixes a bug in typescript, where errors in functions didn't behave correctly Aug 31, 2026
@TimothyJones TimothyJones changed the title feat(functions): Add payload matching for thrown function errors. Also fixes a bug in typescript, where errors in functions didn't behave correctly feat(functions): Add payload matching for thrown function errors. Also fixes a bug in typescript, where errors in function contracts didn't behave correctly Aug 31, 2026
TimothyJones and others added 3 commits August 31, 2026 18:16
…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>
@TimothyJones
TimothyJones merged commit b3f127d into main Aug 31, 2026
15 checks passed
@TimothyJones
TimothyJones deleted the feat/function-error-payload branch August 31, 2026 08:48
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