Skip to content

Commit

Permalink
Refine exit codes
Browse files Browse the repository at this point in the history
- 2 for file not found
- 3 for invalid arguments
- 4 for missing dependencies
- 123 for unknown failures
  • Loading branch information
akaihola committed Jul 28, 2024
1 parent aba2e3a commit edc9f95
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/darker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,8 @@ def main( # pylint: disable=too-many-locals,too-many-branches,too-many-statemen
rev2_repr = (
"the working tree" if revrange.rev2 == WORKTREE else revrange.rev2
)
raise ArgumentError(
Action(["PATH"], "path"),
f"Error: Path(s) {missing_reprs} do not exist in {rev2_repr}",
raise FileNotFoundError(
f"Path(s) {missing_reprs} do not exist in {rev2_repr}"
)

# These paths are relative to `common_root`:
Expand Down Expand Up @@ -631,10 +630,18 @@ def main_with_error_handling() -> int:
"""Entry point for console script"""
try:
return main()
except (ArgumentError, DependencyError) as exc_info:
if logger.root.level < logging.WARNING:
raise
sys.exit(str(exc_info))
except FileNotFoundError as exc_info:
logger.error("%s (2)", exc_info)
return 2
except ArgumentError as exc_info:
logger.error("%s (3)", exc_info)
return 3
except DependencyError as exc_info:
logger.error("%s (4)", exc_info)
return 4
except Exception as exc_info: # pylint: disable=broad-exception-caught
logger.error("%s (123)", exc_info)
return 123


if __name__ == "__main__":
Expand Down

0 comments on commit edc9f95

Please sign in to comment.