Skip to content

Fix deploy command to exit non-zero on deployment failure#119

Merged
titouanmathis merged 4 commits into
mainfrom
fix/deploy-exit-code-on-failure
Jul 1, 2026
Merged

Fix deploy command to exit non-zero on deployment failure#119
titouanmathis merged 4 commits into
mainfrom
fix/deploy-exit-code-on-failure

Conversation

@titouanmathis

Copy link
Copy Markdown
Contributor

Problem

forge deployments deploy (with or without --stream) always exited 0 and recorded status: "success" in the audit log, even when the deployment failed on the server (e.g. a deploy script exiting 1).

Root cause

The failure was detected correctly — deploySiteAndWait() returns status: "failed" and the handler printed ✗ Deployment failed … — but the handler then returned normally instead of throwing. As a result:

  • The command-router write wrapper never hit its catch, so it logged status: "success" to the audit log.
  • Nothing propagated to runCommandhandleError, so the process exited with the default code 0.

Both symptoms stem from the same missing throw. (Note: the audit log's status is control-flow-derived — "did the handler throw" — and is independent of the deployment's own result.data.status.)

Fix

Throw an error on non-success in the deploy handler. This routes through the existing machinery:

  • command-router catch → audit log records status: "error"
  • re-throw → runCommandhandleErrorprocess.exit(1)

The deployment log is now emitted before the throw (in non-stream mode) so failure output is still shown. No changes needed in command-router or deploy-and-wait — they already do the right thing once the handler stops swallowing the failure.

Tests

  • Updated the failing-deploy test to assert process.exit(1) and that the message goes to stderr.
  • Added a test asserting the log is output before failing in non-stream mode.
  • Full suite: 1879 passing; lint, format, typecheck clean.

🤖 Generated with Claude Code

titouanmathis and others added 2 commits July 1, 2026 14:08
The `deployments deploy` handler printed a failure message but returned
normally when the deployment failed, so the process exited 0 and the audit
log recorded status "success". Throw an error on non-success so the failure
propagates to the exit code and audit log via the existing error handling.

Co-authored-by: Claude <claude@anthropic.com>
Co-authored-by: Claude <claude@anthropic.com>
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.45%. Comparing base (1eab1d4) to head (1ad8166).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #119   +/-   ##
=======================================
  Coverage   99.45%   99.45%           
=======================================
  Files         235      235           
  Lines        4031     4033    +2     
  Branches     1016     1031   +15     
=======================================
+ Hits         4009     4011    +2     
  Misses         22       22           
Flag Coverage Δ
unittests 99.45% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

titouanmathis and others added 2 commits July 1, 2026 14:14
Streamed log chunks have no trailing newline, so the success/failure
message was printed on the same line as the last log line. Emit a
separating newline on stdout when streaming.

Co-authored-by: Claude <claude@anthropic.com>
Vite bundled pino and resolved its browser build, which routes log
output to the console via console.log. This printed the audit entry
object to stdout after every write command. Externalize pino so Node
resolves its real node build at runtime and logs go to the audit file.

Co-authored-by: Claude <claude@anthropic.com>
@titouanmathis titouanmathis merged commit 7f77c8e into main Jul 1, 2026
6 of 8 checks passed
@titouanmathis titouanmathis deleted the fix/deploy-exit-code-on-failure branch July 1, 2026 12:31
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