feat(cli): standardize documented exit codes across command dispatch - #764
Open
ajulaybeeb wants to merge 1 commit into
Open
feat(cli): standardize documented exit codes across command dispatch#764ajulaybeeb wants to merge 1 commit into
ajulaybeeb wants to merge 1 commit into
Conversation
Map usage, configuration, network, signing, execution, and environment failures to stable exit codes. Core changes: - ExitCode enum (src/utils/exit_codes.rs): Defined stable, documented exit codes (0: Success, 1: GeneralFailure, 2: Usage, 3: Config, 4: Network, 5: Signing, 6: Execution, 7: Environment) with machine-readable names and descriptions. - determine_exit_code(): Classifier engine that inspects error types, error messages, and cause chains to map error conditions to the appropriate ExitCode variant. - main.rs integration: Replaced generic std::process::exit(1) calls in command dispatch and invalid correlation ID handling with determine_exit_code(&e).exit() and ExitCode::Usage.exit(). Tests & Documentation: - tests/cli_exit_codes.rs: Added 10 unit and integration tests covering enum specification, error classification across all 7 error categories, and cause-chain inspection. - README.md: Added CLI exit codes reference table and shell script error-handling code example. - DEVELOPER_GUIDE.md: Documented exit code architecture, developer guidelines for command handler error returns, and test execution instructions. Closes Nanle-code#672
|
@ajulaybeeb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
starforgeCLI commands for scriptability and CI/CD automationExitCodeenum (src/utils/exit_codes.rs) representing success (0), general failure (1), usage error (2), configuration error (3), network error (4), signing error (5), execution error (6), and environment error (7)determine_exit_code(&anyhow::Error)error classifier that inspects error types, error messages, and cause chainsmain()dispatch to exit withdetermine_exit_code(&e).exit()instead of genericexit(1)tests/cli_exit_codes.rs) and updateREADME.mdandDEVELOPER_GUIDE.mdwith exit code documentationWhy
Issue #672 requires usage, configuration, network, signing, execution, and environment failures to be mapped to stable, documented exit codes. Previously, all command failures exited with generic status code
1(except correlation ID validation which used2). This prevented shell scripts and CI/CD pipelines from distinguishing between transient network glitches, invalid arguments, passphrase authentication failures, or missing local system dependencies.Implementation
src/utils/exit_codes.rs(new)ExitCode(#[repr(i32)]):0(Success): Command executed successfully1(GeneralFailure): Unclassified runtime or execution failure2(Usage): Invalid CLI arguments, syntax, or input parameter3(Config): Configuration file missing, invalid, or schema migration failure4(Network): Network connectivity, RPC node, or Horizon request failure5(Signing): Cryptographic keypair, secret decryption passphrase mismatch, or signature failure6(Execution): Contract WASM compilation, verification, or transaction revert7(Environment): Missing system dependency (e.g. Docker, curl), permission denied, or unsupported host OS/archdetermine_exit_code(): Classification engine that pattern-matches top-level error strings and fullanyhowcause chains to return the matchingExitCodevariantExitCode::exit(): Helper invokingstd::process::exit(self.code())src/main.rsutils::exit_codes::determine_exit_code(&e)and exit withcode.exit()ExitCode::Usage.exit()tests/cli_exit_codes.rs(new, 10 tests)test_exit_code_numeric_values: Verifies numeric i32 code mappings (0 through 7)test_exit_code_names_and_descriptions: Verifies machine-readable names and descriptionstest_classify_usage_errors: Tests classification for bad args, invalid keys, invalid correlation IDstest_classify_signing_errors: Tests classification for secret key errors and passphrase decryption failurestest_classify_network_errors: Tests classification for Horizon, Friendbot, and RPC connection/timeout errorstest_classify_config_errors: Tests classification forconfig.tomlparse errors and unsupported networkstest_classify_execution_errors: Tests classification for WASM errors, contract compilation, and simulation revertstest_classify_environment_errors: Tests classification for Docker, permission, and unsupported OS/arch errorstest_classify_general_failure_fallback: Tests fallback to code 1 for unclassified runtime errorstest_classify_chained_context_error: Tests classification over nestedanyhowcause chainsDocumentation
README.md: Added CLI exit codes reference matrix detailing code values, names, descriptions, triggers, and shell script usage examplesDEVELOPER_GUIDE.md: Added Standardized CLI Exit Codes architecture overview, error return guidelines for command handlers, and test commandsTesting
Ran automated integration suite: