Added granular, meaningful exit codes #10973
Closed
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.
This pull request introduces a new, more granular exit code system for the Docfx CLI, making it easier to diagnose build failures and integrate with CI/CD pipelines. It adds command-line options to control exit code behavior, implements logic to categorize errors, and updates documentation to explain the changes.
Exit Code System and CLI Options:
ExitCodeenum (src/docfx/Models/ExitCode.cs) defining specific exit codes for different error categories (e.g., config, input, metadata, template, user-cancelled, etc.), replacing the previous binary success/failure model.LogOptions(src/docfx/Models/LogOptions.cs):--strict(returns exit code 1 if warnings are present) and--legacy-exit-codes(returns 0 for success, -1 for any error, for backward compatibility).Error Categorization and Exit Code Logic:
ExitCodeHelper(src/docfx/Models/ExitCodeHelper.cs) to determine the appropriate exit code based on the type of error encountered, strict mode, legacy mode, and cancellation state. It also maps exceptions to exit codes and resets state for each command.Loggerclass (src/Docfx.Common/Loggers/Logger.cs) to track error categories (config, build, metadata, template, input) and reset their state between runs. Errors are now categorized using the error code pattern. [1] [2] [3]src/docfx/Models/CommandHelper.cs,src/docfx/Program.cs) to use the new exit code system, handle cancellation (Ctrl+C), and ensure proper exit code is returned in all cases. [1] [2] [3] [4]Documentation:
docs/docs/config.mdexplaining the exit codes, command-line options, and usage examples for CI/CD pipelines.