Skip to content

Update dsc.exe to have single process exit point - #1693

Open
Steve Lee (SteveL-MSFT) wants to merge 4 commits into
PowerShell:mainfrom
SteveL-MSFT:dsc-main-exit
Open

Update dsc.exe to have single process exit point#1693
Steve Lee (SteveL-MSFT) wants to merge 4 commits into
PowerShell:mainfrom
SteveL-MSFT:dsc-main-exit

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

PR Summary

There's a known issue using std::process::exit() on Windows that prevents code coverage data from being collected. Fix is to switch to having main() return ExitCode which accomplishes the same thing. The previous code in dsc.exe had many calls to exit() which is not ideal since there are now multiple ways for the process to exit. Changed many functions in the exe to return a Result<> instead which wraps the exit code it would have returned so now there's a single place where that gets returned.

ExitCode::from() takes a u8 so changed the consts to u8 instead of i32.

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.

Pull request overview

This PR refactors the dsc CLI to avoid calling std::process::exit() throughout the codebase, instead propagating std::process::ExitCode via Result so the process exits through a single return path (improving Windows code coverage collection).

Changes:

  • Replaces many exit(<code>) calls with Result<_, ExitCode> propagation across CLI helper functions and subcommand handlers.
  • Updates CLI exit code constants to u8 to align with ExitCode::from(u8).
  • Adjusts output and input utilities (write_object, get_input, config root initialization) to return Result rather than terminating the process.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
dsc/src/util.rs Converts exit-code constants to u8 and updates utility helpers to return Result<_, ExitCode> instead of exiting.
dsc/src/subcommand.rs Updates subcommand entrypoints/helpers to return Result<(), ExitCode> and propagate failures upward.
dsc/src/resource_command.rs Changes resource command handlers to return Result<(), ExitCode> and replace exit() with propagated ExitCode.
dsc/src/main.rs Makes main() return ExitCode and routes subcommands through dsc_main() -> Result<(), ExitCode>.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dsc/src/main.rs Outdated
Comment thread dsc/src/subcommand.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants