Skip to content

Change from calling exit() to returning ExitCode from Rust executables - #1743

Open
Steve Lee (SteveL-MSFT) wants to merge 4 commits into
mainfrom
stevel-msft-rust-exitcode-migration
Open

Steve Lee (SteveL-MSFT) wants to merge 4 commits into
mainfrom
stevel-msft-rust-exitcode-migration

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

Rust executables that call std::process::exit bypass normal process cleanup, preventing code coverage data from being flushed. This change returns std::process::ExitCode from executable entry points instead.

The migration propagates failures through helper APIs to each main function while preserving existing status codes and output behavior. It also constrains the dsctest exit-code fixture to the u8 range supported by ExitCode and updates the DSC resource creation skill to require this pattern for new Rust resources.

Validated with the repository build and Clippy across the affected Rust projects.

Return exit statuses through Rust main functions so normal process cleanup can flush code coverage data. Update resource authoring guidance to require the same pattern.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 02: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

The environment-variable unit tests still expect Option and will not compile after parse_input_arg begins returning Result.

3 open findings
What changed in this PR

Migrates Rust executables from process::exit to returned ExitCode, enabling normal cleanup and coverage flushing.

Changes:

  • Propagates exit codes through resource and test helper APIs.
  • Restricts dsctest exit-code inputs to u8.
  • Documents the pattern for newly created resources.
File Description
y2j/​src/​main.rs Returns conversion failures through ExitCode.
tools/​dsctest/​src/​main.rs Propagates fixture failures from run.
tools/​dsctest/​src/​export_schema.rs Returns schema-export errors.
tools/​dsctest/​src/​exit_code.rs Restricts fixture codes to u8.
tools/​dsctest/​src/​adapter.rs Returns normally after streamed output.
resources/​WindowsUpdate/​src/​main.rs Returns operation status codes.
resources/​windows_service/​src/​main.rs Propagates helper failures.
resources/​windows_firewall/​src/​main.rs Propagates helper failures.
resources/​sshdconfig/​src/​main.rs Returns command status.
resources/​runcommandonset/​src/​utils.rs Makes helper failures recoverable.
resources/​runcommandonset/​src/​main.rs Converts helper errors to exit codes.
resources/​process/​src/​main.rs Returns operation status.
resources/​osinfo/​src/​main.rs Centralizes errors through run.
resources/​filecontent/​src/​main.rs Returns parsing and resource failures.
resources/​environment_variable/​src/​main.rs Propagates parsing and serialization failures.
resources/​dscecho/​src/​main.rs Returns schema or echo status.
resources/​dism_dsc/​src/​main.rs Returns dispatch status.
adapters/​group_policy_template/​src/​main.rs Returns adapter status codes.
.github/​skills/​create-dsc-resource/​SKILL.md Documents the ExitCode pattern.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread resources/environment_variable/src/main.rs
Comment thread resources/runcommandonset/src/utils.rs Outdated
Comment thread resources/windows_service/src/main.rs Outdated
Update environment variable tests for Result-returning argument parsing and correct helper documentation to describe propagated exit codes.

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

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

😐 Code Coverage Report

Changed Code Coverage

75% (70%+ coverage)

Metric Value
Changed lines analyzed 286
Lines covered by tests 215
Coverage percentage 75%

🔵 Full Codebase Coverage

83% (good)

Metric Value
Total executable lines 19532
Lines covered by tests 16295
Coverage percentage 83%

Changed code coverage measures only Rust lines added/modified in this PR.
Full codebase coverage measures all instrumented Rust lines across the project.

Exercise invalid input, missing instance, and command failure paths across dsctest and cross-platform Rust resources so changed-line coverage includes the new ExitCode propagation branches.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@SteveL-MSFT Steve Lee (SteveL-MSFT) changed the title Return ExitCode from Rust executables Change from calling exit() to returning ExitCode from Rust executables Oct 8, 2026
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Copilot resolve the merge conflicts in this pull request

…code-migration

# Conflicts:
#	resources/dism_dsc/src/main.rs

Co-authored-by: SteveL-MSFT <11859881+SteveL-MSFT@users.noreply.github.com>

Copilot AI commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Copilot resolve the merge conflicts in this pull request

Resolved the conflict in resources/dism_dsc/src/main.rs, preserving main's --input handling and the PR's ExitCode behavior. Merge commit: 231959c. Targeted validation was attempted but blocked by missing grammar binding files.

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.

3 participants