Skip to content

entrypoint: report errors in the engine's function error file - #144

Merged
vito merged 4 commits into
mainfrom
function-error-file
Nov 24, 2026
Merged

vito merged 4 commits into
mainfrom
function-error-file

Conversation

@vito

@vito vito commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Depends on dagger/dagger#15249, which adds the engine's function error file (DAGGER_FUNCTION_ERROR_PATH) and the golden tests this is checked against (dagql/idtui, sdks-typescript-*). The TypeScript counterpart of dagger/go-sdk#113, dagger/python-sdk#93 and dagger/java-sdk#47.

This branch includes #143 (generated Dang entrypoints name cache policies in GraphQL's spelling), which is still open: the fixture doesn't load without it. Merge #143 first, or this along with it.

What users saw

Under a module entrypoint, the dispatcher replied on stdout, which the function's own console.log shares:

  • a function that logged and returned failed with JSON.decode: invalid JSON;
  • one that logged and threw lost its message to exit code: 2;
  • a module that didn't compile failed the process before the dispatcher ran, as exit code: 1, with node's crash dump in the hidden logs;
  • every failure dumped console.error(e) (for an API error, the whole GraphQL response) and the reply JSON onto the function's row;
  • ExecError wasn't exported from a module's @dagger.io/dagger, so it couldn't be caught.

What changes

  • Result in a file. The dispatcher writes the result to /dagger/result.json, named on its command line, and call() reads it back. stdout is the function's again.
  • Errors in the engine's file. On an engine that sets DAGGER_FUNCTION_ERROR_PATH, a failed call writes {"message", "values"} there and exits 2. The message is full, with its [traceparent:…] origins. The values are the error's own extensions, else those of the API error it wraps through cause. call() raises the exec error unchanged when it carries the engine's functionError, so callers get a typed error, values and all. Older engines, or a file that can't be written, get the previous console.error(e) plus a ::dagger-function-error:: marker on stderr, as go-sdk prints it.
  • Short stack traces. In error-file mode, the call's logs get only the module's own frames. Node internals, node_modules, *.gen.*, clients/ and the dispatcher itself are dropped, causes print as Caused by:, and traceparents are stripped. An API error with an origin prints nothing: the engine shows the failing call with its own logs.
  • Load errors are reported. The dispatcher imports the module's code for its types only (import type), and loads it with import() once it is running. A compile error from tsx (TransformError) reports esbuild's summary as the message, and its error lines as the logs. Bun's AggregateError lists its BuildMessages with their positions.
  • ExecError and friends are exported from the bundled barrel.
  • No prebuild. tsx compiles at run time, so there is no build step to show under build <module>.

Testing

  • go test ./... in helpers/codegen; the dispatch and Dang goldens were regenerated.
  • The generated dispatcher was run in node:24 + tsx and oven/bun:1.3.0 with a stubbed SDK, covering: success after a log; a native throw; an ExecError with an origin; a wrapped ExecError; a syntax error; and the old-engine marker.
  • The 17 sdks-typescript-* goldens on core, idtui: readable errors from entrypoint SDK modules dagger#15249 pass with this pinned.
  • Not run: the e2e and runtimes checks. They need a published engine image of the CLI's version, which doesn't exist yet. Their recipe assertions were updated.

vito added 4 commits November 21, 2026 20:30
A generated Dang entrypoint for a function with @func({ cache: "session" })
fails to load: `field "PerSession" not found in Dagger.FunctionCachePolicy`.
The Dang renderer emitted the TypeScript client's member names; Dang
names enum members by their GraphQL values. Emit PER_SESSION, NEVER and
DEFAULT instead.

Same change as #142, which was closed unmerged.

Signed-off-by: Alex Suraci <[email protected]>
bundle/index.ts, which every module gets as clients/dagger/index.ts, names
its exports one by one and left the error classes out, so a module could not
import ExecError to catch a failed exec and read its exit code. The library
barrel already exports them, through `export * from "@dagger.io/session"`.

Signed-off-by: Alex Suraci <[email protected]>
A dispatcher under a module entrypoint replied on stdout, which the
function's own console.log shares: a function that logged and returned
failed with "JSON.decode: invalid JSON", and one that logged and threw lost
its message to "exit code: 2". A module that didn't compile failed the
process before the dispatcher ran, as "exit code: 1".

- The result goes to /dagger/result.json, named on the command line, which
  call() reads back once the exec succeeded.
- A failed call's error goes to the function error file the engine names in
  DAGGER_FUNCTION_ERROR_PATH (dagger/dagger#15249): the full message, origins
  kept, and the extensions of the API error it is or wraps, followed by exit
  code 2. call() raises the exec error unchanged when it carries the
  engine's functionError. An engine without the file gets a
  `::dagger-function-error::` marker on stderr, as go-sdk prints it.
- In error-file mode the call's logs get a short stack trace of the module's
  own frames only, causes included and traceparents stripped, and nothing
  for an API error whose origin the engine shows. A TransformError, the
  module failing to compile, is esbuild's own error lines, with its summary
  as the call's message.
- The module's code is imported for its types only and loaded with import()
  by loadModule, so a load or compile error is reported like any other.

There is no prebuild: tsx compiles at run time, so there is no build step to
show under `build <module>`.

Signed-off-by: Alex Suraci <[email protected]>
- Bun's AggregateError for a module that doesn't build lists the
  BuildMessages it holds, each with its position, and a thrown non-Error
  with a message, such as Bun's ResolveMessage, is reported by its message
  rather than as JSON.
- A short stack trace stops at an API error: its cause is graphql-request's
  ClientError, whose message is the whole response and request.
- An error's own extensions are its values, as the builtin runtime's
  formatError reports them; only without them do the values come from an
  API error it wraps.
- The old-engine marker carries a compile error's whole message, since an
  older engine doesn't show the logs that hold its details.
- Comments and the design doc describe the result file and the function
  error file instead of the stdout reply.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit to dagger/dagger that referenced this pull request Nov 22, 2026
Pin typescript-sdk to dagger/typescript-sdk#144 (28249a5, on top of #143)
and regenerate the TypeScript fixture. Its dispatcher returns the result in
/dagger/result.json instead of on stdout, writes a function's error to the
engine's DAGGER_FUNCTION_ERROR_PATH, and loads the module's code itself, so
a compile error is reported as the call's error; its entrypoint raises the
exec error that carries it as it is. The module's @dagger.io/dagger exports
ExecError now, so fail-exec-wrapped catches one and wraps it with a cause,
as the other fixtures do. The clients/sdk-dep client is kept as it was:
generation from this checkout re-targets it.

Goldens:
- fail-native: a short stack trace, the error and the user's one frame, as
  Java and Python show one.
- fail-exec-wrapped (today's output, not a target): the cause chain, each
  part through the user's frame only, and no reply JSON, traceparents or
  "call module entrypoint" row. It no longer races, so it isn't Flaky, and
  the sdkFixture racy field goes with it.
- broken-default: esbuild's line is 84:5.

The other targets pass unchanged, log-success included. Every
sdks-typescript golden passes.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito marked this pull request as ready for review November 22, 2026 20:33
@vito
vito merged commit 73806b6 into main Nov 24, 2026
6 checks passed
vito added a commit to dagger/dagger that referenced this pull request Nov 24, 2026
Pin typescript-sdk to dagger/typescript-sdk#144 (28249a5, on top of #143)
and regenerate the TypeScript fixture. Its dispatcher returns the result in
/dagger/result.json instead of on stdout, writes a function's error to the
engine's DAGGER_FUNCTION_ERROR_PATH, and loads the module's code itself, so
a compile error is reported as the call's error; its entrypoint raises the
exec error that carries it as it is. The module's @dagger.io/dagger exports
ExecError now, so fail-exec-wrapped catches one and wraps it with a cause,
as the other fixtures do. The clients/sdk-dep client is kept as it was:
generation from this checkout re-targets it.

Goldens:
- fail-native: a short stack trace, the error and the user's one frame, as
  Java and Python show one.
- fail-exec-wrapped (today's output, not a target): the cause chain, each
  part through the user's frame only, and no reply JSON, traceparents or
  "call module entrypoint" row. It no longer races, so it isn't Flaky, and
  the sdkFixture racy field goes with it.
- broken-default: esbuild's line is 84:5.

The other targets pass unchanged, log-success included. Every
sdks-typescript golden passes.

Signed-off-by: Alex Suraci <[email protected]>
TomChv added a commit that referenced this pull request Nov 25, 2026
`e2e/sdk/helper-tests-check` is red on main: `go test ./...` in
helpers/codegen fails TestGenerateDangEntrypointCachePolicy (3 subtests)
and TestGenerateEntrypointDispatchLoadsModuleCode.

Neither is a regression in #120's code, and neither PR could have caught
it. #120 made every generator that renders a module's own declarations
ask the engine for their names, and added `Naming` to each test that
builds a generator config. Its branch predates both of these tests:

- dang_entrypoint_cache_policy_test.go arrived with #143.
- TestGenerateEntrypointDispatchLoadsModuleCode arrived with #144.

Both merged after #120's CI ran, git merged all three cleanly, and the
combination was never tested. Without a naming context the dang
entrypoint finds no main object among typedef_smoke.json's objects, and
the dispatcher cannot name the fixture's own interface.

Both now use `smokeNaming()`, as every other test on that fixture does.

Signed-off-by: Tom Chauveau <[email protected]>
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.

2 participants