Skip to content

fix(core): surface underlying exec error when merging generator changesets - #13664

Merged
vito merged 1 commit into
dagger:mainfrom
TomChv:fix/dagger-generate-clear-error
Jul 17, 2026
Merged

vito merged 1 commit into
dagger:mainfrom
TomChv:fix/dagger-generate-clear-error

Conversation

@TomChv

@TomChv TomChv commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Problem

When a generator's changeset evaluates lazily and its backing exec fails, dagger generate leaves you with a content-free summary:

Error: compute their paths: evaluate changeset directories: exit code: 3

It names neither the command that failed nor its stderr. The failing exec's stderr does still stream into the live progress tree, but the error summary — the artifact that survives a failed run and lands in CI logs — drops it, so the user has to scroll a (possibly collapsed) tree or re-run the changeset by hand.

Fixes #13606.

Why

The exec produces an *ExecError (Cmd, Stderr, ExitCode), but ExecError.Error() returns only "exit code: N" — the command and stderr live on the struct / Extensions(), never in the message. The changeset merge (WithChangeset / WithChangesets) then wraps it with bare %w context. The exec is forced lazily deep inside the merge, so the summary is all that's left.

Fix

Lift the *ExecError's command, exit code, and stderr into the message at the merge boundary via a small mergeEvalError helper, applied in WithChangeset, WithChangesets, and checkAllPairwiseConflicts. The *ExecError stays in the %w chain so its extensions/origin still propagate.

The shared direct-eval path (ComputePaths / withMountedDirs / IsEmpty, used by dagger call … is-empty) is deliberately left untouched — the TUI already renders its exec span's stderr there, so enriching it would double-print.

Tests

  • Unit: TestMergeEvalError (core/changeset_test.go) — cmd+stderr lifted, chain preserved, plain/bare errors unchanged.
  • Integration: TestGeneratorLazyExecFailureSurfacesStderr (core/integration/generators_test.go) — drives real dagger generate against a lazily-failing exec. Verified it fails on main (summary is bare exit code: 3) and passes with the fix.

Design notes in hack/designs/generate-surface-exec-error.md.

@TomChv

TomChv commented Jul 16, 2026 •

Copy link
Copy Markdown
Member Author

🚧 This PR requires manual testing before it's ready for review.

EDIT: manual testing DONE 🚀

The two new automated tests pass on a dev engine, and I verified the integration test fails on main (bare exit code: N) and passes with the fix. What still needs a human pass:

  • Reproduce the original issue for real — a failing SDK codegen under dagger generate (e.g. dagger generate golang …) — and confirm the error now names the command + stderr.
  • Sanity-check the rendered message in the pretty TUI (not just --progress=plain): formatting, no stderr duplication against the live span tree, and that multi-generator (octopus) merges surface the failing one clearly.
  • Confirm no regression in the direct dagger call … is-empty path (left intentionally untouched).

Repro steps are in the PR description / hack/designs/generate-surface-exec-error.md. Leaving as draft until that manual pass is done.

@TomChv
TomChv force-pushed the fix/dagger-generate-clear-error branch from abd932f to 7a3471a Compare July 16, 2026 17:28
@TomChv
TomChv marked this pull request as ready for review July 17, 2026 09:45
@TomChv

TomChv commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

I did a test comparing the output from the current version (beta.6) and my version in the playground and we can clearly see the error from the module. Is that what is expected or do we want to show something else?

Screenshot 2026-07-17 at 11 45 04

Trace on dagger.cloud

@TomChv
TomChv force-pushed the fix/dagger-generate-clear-error branch 3 times, most recently from 949ff0d to a629b0e Compare July 17, 2026 15:23
@TomChv

TomChv commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Good call on the golden coverage — doing it surfaced that the fix wasn't actually enough. 👇

Expanding the TestTelemetry/TestGolden flow to generate (it was call/check only) showed the merge error was still hidden in --progress=report/TUI, even with the plain-output fix. The merge error carried the *ExecError's origin annotation, and renderStepError suppresses a span's own message when it has error origins (it expects to render the origin span instead) — but the failing exec is forced lazily during the merge and never becomes a visible span, so the TUI rendered nothing.

Fixed by making the merge error self-contained and origin-free (a small mergeExecError whose Error() names the command + exit code + stderr, Unwrap still exposes the *ExecError for errors.As/extensions). The frontend now renders it inline.

New golden (generate-fail), so it's visible in the diff here:

✔ viztest:generate-fail
Error: compute their paths: sh -c echo boom >&2; exit 3 exited with code 3
boom

Landed as:

  • Generate mode in the golden flow + a GenerateFail generator in viztest
  • the generate-fail golden
  • unit + integration coverage for the plain-output path

Squashed into one commit and rebased on main. Still draft pending a final manual pass, but the automated + golden coverage is in.

@TomChv
TomChv force-pushed the fix/dagger-generate-clear-error branch from a629b0e to 793802e Compare July 17, 2026 15:59
@@ -0,0 +1,5 @@
Expected stderr:

✔ viztest:generate-fail X.Xs ⡀⡄⡆⡇⣇⣧⣷⣿

@vito vito Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting that this still shows a green check. Makes me think we're fixing at the wrong layer.

IMO mergeEvalError shouldn't be necessary at all - if we can correctly attribute the exec failure back to this check span, the TUI should be able to show a nice rolled-up error attributed to the check; instead of a false-green check with an error message constructed from the captured stdout/stderr, you'd have a red X with the logs surfaced through the span tree.

One thing worth trying: right now "running the generator locally" (which happens within the span) actually just grabs the Changeset which is lazy. Maybe each generator should force-sync() it?

dagger/core/modtree.go

Lines 497 to 502 in dc12c3a

func (node *ModTreeNode) runGeneratorLocally(ctx context.Context) (dagql.ObjectResult[*Changeset], error) {
var changes dagql.ObjectResult[*Changeset]
if err := node.DagqlValue(ctx, &changes); err != nil {
return dagql.ObjectResult[*Changeset]{}, err
}
return changes, nil

It'll have to sync() eventually and these already run in parallel so I don't see a reason to defer it.

Though now that I look at Changeset.Evaluate it's a no-op - maybe it should evaluate its Directories?

When a `+generate` function's changeset evaluates lazily and its backing exec
(e.g. SDK codegen) fails, `dagger generate` hid the failure: the generator
rendered as a green check and the user got a bare "exit code: N" with no
command or stderr, in the TUI as well as plain output.

Root cause: `runGeneratorLocally` grabbed the lazy Changeset but never forced
it, and `Changeset.Evaluate` was a no-op -- so the exec ran later, during the
merge, outside the generator's span: misattributed, with its logs hidden.

Force the changeset to evaluate inside the generator's span:
- `Changeset.Evaluate` now evaluates its before/after directories, so
  `changeset.sync` actually forces (its intended semantics).
- `runGeneratorLocally` syncs the changeset after grabbing it; generators
  already run in parallel and it has to sync eventually.

The generator now goes red and the exec error is attributed to it. Also keep a
rolled-up span's logs on failure in the pretty frontend (previously shown only
while running), so the exec's stderr survives in the final report instead of
collapsing to a bare status.

Tests:
- integration: real `dagger generate` over a lazily-failing generator surfaces
  the command, stderr, and exit code (plain output).
- golden: a Generate mode in the TestTelemetry golden flow (was call/check
  only) + a GenerateFail generator in viztest; the generate-fail golden pins
  the red row with the exec's stderr rolled up under it.

Design notes in hack/designs/generate-surface-exec-error.md.

Fixes dagger#13606

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the fix/dagger-generate-clear-error branch from 793802e to 273d3f1 Compare July 17, 2026 17:18
@vito
vito merged commit d77df42 into dagger:main Jul 17, 2026
87 checks passed
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.

dagger generate hides the underlying exec error

2 participants