Skip to content

Return non-zero exit code when commands fail - #1992

Open
waldekmastykarz wants to merge 6 commits into
dotnet:mainfrom
waldekmastykarz:fix-1959-exit-codes
Open

waldekmastykarz wants to merge 6 commits into
dotnet:mainfrom
waldekmastykarz:fix-1959-exit-codes

Conversation

@waldekmastykarz

@waldekmastykarz waldekmastykarz commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1959

cert ensure, config new, config get and mocks from-http-responses logged an error but exited with code 0, breaking scripts and agents that rely on exit codes. They now exit with 1 on failure (matching cert remove).

  • cert ensure: returns 1 when trusting the certificate throws
  • config new: returns 1 when creating the file fails
  • config get: returns 1 when the config isn't found in the samples repo or the download fails
  • mocks from-http-responses: returns 1 for missing args / no matching files, and when any input file fails to parse (mocks for successfully parsed files are still written)

Tests

Added CommandExitCodeTests (process-level, in DevProxy.Integration.Tests) covering success and failure for config new and mocks from-http-responses, and failure for config get (routed through an unreachable proxy, so no network access is needed). The failure tests fail on main and pass with this change. All test suites pass.

`cert ensure`, `config new` and `mocks from-http-responses` logged
errors but exited with code 0. They now return 1 on failure.
`mocks from-http-responses` also returns 1 when any input file fails to
parse (still writing mocks for the files that succeeded).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fcec9529-b9a7-41f7-9e1d-fdb9fc72cd4b
Copilot AI balanced review requested due to automatic review settings October 21, 2026 13:57
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 21, 2026 13:57

Copilot AI left a comment

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.

🟡 Changes recommended

Logged certificate trust failures and non-throwing parse errors can still produce exit code 0.

2 open issues
What changed in this PR

Improves Dev Proxy command exit codes so scripts can detect failures.

Changes:

  • Returns failure codes for certificate and configuration exceptions.
  • Tracks mock input failures while preserving successfully generated mocks.
  • Adds process-level success and failure tests.
File Description
DevProxy/​Commands/​ConfigCommand.cs Propagates configuration creation exit codes.
DevProxy/​Commands/​CertCommand.cs Returns failure when certificate trust throws.
DevProxy.Plugins/​Mocking/​MockResponsePlugin.cs Reports missing inputs and caught parsing failures.
DevProxy.Integration.Tests/​CommandExitCodeTests.cs Tests configuration and mock command exit codes.

Review effort: Balanced

Comment thread DevProxy.Plugins/Mocking/MockResponsePlugin.cs
Comment thread DevProxy/Commands/CertCommand.cs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fcec9529-b9a7-41f7-9e1d-fdb9fc72cd4b

Copilot AI left a comment

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.

🔵 Needs a closer look

Logged parsing errors that do not throw can still leave mock generation reporting success.

2 open issues

Review effort: Balanced

waldekmastykarz and others added 2 commits October 26, 2026 11:31
Preserve generated mock contents while reporting malformed headers and JSON bodies as failures. Addresses review feedback on dotnet#1992.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Return helper results to distinguish installation failure from success, while preserving best-effort automatic trust. Update the Trust contract and cover failure exit codes. Addresses dotnet#1992 review feedback.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

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.

🟢 Approval recommended

The changes propagate failures correctly, preserve existing fallback behavior, and include targeted regression coverage with no unresolved blocking findings.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI left a comment

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.

🟢 Approval recommended

The changes address the identified failure paths, preserve existing fallback behavior, and include regression coverage with no unresolved blocking findings.

No open issues 🎉

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

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.

🟢 Approval recommended

The focused failure-propagation changes preserve existing behavior and include regression coverage, with no unresolved blocking issues.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Some commands exit with code 0 on failure

2 participants