Skip to content

Report function errors in the engine's error file - #49

Open
vito wants to merge 5 commits into
mainfrom
function-error-file
Open

vito wants to merge 5 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-php-*). The PHP counterpart of dagger/go-sdk#113, dagger/python-sdk#93, dagger/java-sdk#47 and dagger/typescript-sdk#144.

This branch includes #48 (sdk-helpers v1.0.9 → v1.0.11), which is still open: nothing generates without it. Merge #48 first, or this along with it.

What users saw

Under a module entrypoint:

  • the generated entrypoint raised the dispatcher's whole stderr as the function's error, so the message was the function's own stderr lines plus a full PHP stack trace through CallDispatcher and ReflectionMethod;
  • a function that called exit(3) failed with the message php function stderr (its last stderr line), and its exit code was lost;
  • a function whose withExec failed echoed the inner exec's stdout and stderr onto the function's row and exited with the inner code, rather than the caller getting a typed exec error.

What changes

  • 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 (new Dagger\Module\FunctionError). The message is complete, with its [traceparent:…] origins. The values are the extensions of the QueryError the error is or wraps (through getPrevious()), so a caller gets a typed ExecError, exit code and output included. The generated call() raises the exec error unchanged when it carries the engine's functionError.
  • Short stack traces. In error-file mode the function's logs get only a short trace through the module's own frames, leaving out the SDK, its generated clients and vendor/, in PHP's own form (RuntimeException: … in src/Foo.php:44, Stack trace:, previous errors first with Next). A module file that doesn't parse reads PHP Parse error: … on line N, as PHP prints it. An API error whose origin the engine already shows prints nothing.
  • Fatal errors. A fatal error such as exhausted memory has no Throwable to catch, so a shutdown function reports it in the file or with the marker.
  • prebuild. The entrypoint declares prebuild: the module with its Composer dependencies installed. The engine builds it ahead of the call, as build <module>, so a failed composer install shows there with Composer's own output.
  • Older engines keep working as before. They get the full trace and a last ::dagger-function-error:: marker line on stderr, which call() reads, plus the failed exec's output echoed as before. Without a marker (a function that exits, or a failed install), call() raises the exec's stderr unless the engine marks the module process.

Not changed (deferred)

  • The generated client still sends every default argument (Container.from(address: "alpine", version: "", …)), so calls render with all of them.
  • There is still no function cache policy.

Testing

  • Unit tests (FunctionErrorTest, DangEntrypointRendererTest), PHPStan and PHPCS: dagger check e2e/sdk-unit-check e2e/sdk-analysis-check e2e/sdk-style-check.
  • core, idtui: readable errors from entrypoint SDK modules dagger#15249's TestTelemetry/TestGolden/sdks-php-* goldens all pass against this branch.
  • The e2e checks weren't run: they need a published engine of the CLI's version.

vito added 3 commits November 21, 2026 20:10
sdk-helpers v1.0.9 no longer compiles under current Dang: its
main.dang:147 writes a nullable type pattern in a rescue arm, which
is now rejected ("a type pattern is the non-null type its arm binds:
write `error: Error! =>`"). Every php-sdk generation fails on it.
v1.0.11, which go-sdk already uses, fixes it.

Signed-off-by: Alex Suraci <alex@dagger.io>
On an engine that sets DAGGER_FUNCTION_ERROR_PATH (dagger/dagger#15249), a
failed call writes {"message", "values"} there and exits 2: the message in
full, with its [traceparent:…] origins, and the values the extensions of the
QueryError it is or wraps, so a caller gets a typed ExecError. The generated
entrypoint raises the exec error unchanged when it carries the engine's
functionError. Older engines, or a file that can't be written, get the full
trace plus a ::dagger-function-error:: marker line on stderr, which the
entrypoint reads; without one, as when the function exits by itself, the
exec's own error, exit code and all, is raised. Before, the entrypoint
raised the dispatcher's whole stderr as the message, and a call exited with
the inner exec's code.

In error-file mode the function's logs get only a short trace, through the
module's own frames (not the SDK's, its generated clients' or vendor/'s),
previous errors first, without origins; a file that doesn't parse reads as
PHP reports it. An API error whose origin the engine shows prints nothing.

The entrypoint also declares prebuild, the module with its Composer
dependencies installed, so the engine builds it as the module's build and a
failed install shows under it with Composer's output; call() syncs it before
the rescue for the same reason.

Signed-off-by: Alex Suraci <alex@dagger.io>
From review. On an engine without the function error file, which is every
released one:

- the marker fallback writes a failed exec's stdout and stderr, which the
  error is or wraps, to the dispatcher's own streams again, as before;
- a dispatcher exec that failed without a marker, such as a function that
  exits, raises the exec's stderr as before, unless the engine marks the
  module process (moduleProcess), which then shows the exec's logs and
  exit code with its error;
- so does a failed Composer install, which such an engine doesn't build as
  prebuild ahead of the call.

A fatal error (exhausted memory, a class that can't be declared) ends the
script with no Throwable to catch: a shutdown function now reports it in
the file, or with the marker. PHP shows the error itself.

Signed-off-by: Alex Suraci <alex@dagger.io>
vito added a commit to dagger/dagger that referenced this pull request Nov 22, 2026
dagger/php-sdk#49's review fixes, for engines without the function error
file and for PHP's fatal errors. No golden changes: all 17 sdks-php
goldens pass.

Signed-off-by: Alex Suraci <alex@dagger.io>
vito added 2 commits November 22, 2026 09:57
From review. The shutdown handler that reports a fatal error had no memory
left after the commonest one, exhausted memory: autoloading FunctionError
there failed a second time. FunctionError is now made, and the error path
read, before the function runs, and the handler frees 256 KiB it reserved
first. Taking the module root up front also keeps a function's chdir() from
moving where vendor/ is looked for.

Signed-off-by: Alex Suraci <alex@dagger.io>
From review. Exhausting memory with a growing array leaves the shutdown
function enough memory without the reserve, so that test passed without it.
Exhausting it by deep recursion does not: that case fails with a reserve of
0, so it now covers the reserve, beside the array case.

Signed-off-by: Alex Suraci <alex@dagger.io>
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