Commit ca1c009
fix(run): propagate the Actor's non-zero exit code (#1195)
## What & why
`apify run` exited with code `0` even when the Actor failed. The `catch`
block wrapping `execWithLog` in `RunCommand` read `stderr` but never set
`process.exitCode` or re-threw (it held only a `TODO`), so the error was
swallowed and the command framework's `process.exitCode ||= 1` never
fired.
This silently broke CI and shell chains like `apify run && deploy` — a
failing Actor looked successful to any caller inspecting the exit code.
Fixes #1190
Fixes #1180
## Change
In the `catch` block, forward the child's exit code:
```ts
} catch (err) {
process.exitCode = (err as ExecaError).exitCode ?? 1;
}
```
- Preserves the Actor's **exact** exit code (e.g. `process.exit(10)` →
CLI exits `10`).
- Falls back to `1` for signal-killed children, where
`ExecaError.exitCode` is `undefined`.
- No change to error output — `execWithLog` already prints the message
and the Actor's own stdout/stderr is inherited regardless. Only the exit
code was being lost.
## Tests
Added a scenario test
(`test/local/__fixtures__/commands/run/javascript/propagates-non-zero-exit-code.test.ts`)
following the existing fixture convention: it scaffolds a
`project_empty` Actor, copies in a failing `main.js` fixture that exits
`10`, runs it, and asserts the CLI's `process.exitCode` is `10`.
Verified TDD red → green, plus end-to-end with the built CLI:
| | Actor stderr shown | Error line shown | Exit code |
|---|---|---|---|
| Before | ✅ | ✅ | `0` ❌ |
| After | ✅ | ✅ | `10` ✅ |
`lint`, `format`, `build`, and `test:local` all pass; existing `run`
tests unaffected.
## Follow-up
Exit-code handling for `execWithLog` children is inconsistent across
commands (`run.ts`, `create.ts`, `upgrade.ts` each differ), and
`exec.ts` discards the friendly error it builds. Tracked in #1196 — out
of scope for this fix.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 51089bd commit ca1c009
3 files changed
Lines changed: 57 additions & 5 deletions
File tree
- src/commands
- test/local/__fixtures__/commands/run/javascript
- sources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
455 | 453 | | |
456 | 454 | | |
457 | 455 | | |
| |||
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments