Skip to content

Commit

Permalink
Change numbers - usage error is 2, uncagetorized is now 11.
Browse files Browse the repository at this point in the history
  • Loading branch information
olsen232 committed Apr 15, 2020
1 parent 79dc6a5 commit 703ede8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
4 changes: 0 additions & 4 deletions sno/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
clone,
commit,
diff,
exceptions,
init,
fsck,
merge,
Expand All @@ -26,9 +25,6 @@
from .exec import execvp


click.exceptions.UsageError.exit_code = exceptions.INVALID_ARGUMENT


def print_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
Expand Down
3 changes: 2 additions & 1 deletion sno/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def get_commit_message(repo, wc_changes, quiet=False):
subprocess.check_call(editor_cmd, shell=True)
except subprocess.CalledProcessError as e:
raise SubprocessError(
f"There was a problem with the editor '{editor}': {e}"
f"There was a problem with the editor '{editor}': {e}",
called_process_error=e,
) from e

with open(commit_editmsg, "rt", encoding="utf-8") as f:
Expand Down
9 changes: 7 additions & 2 deletions sno/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
NotYetImplemented,
NotFound,
NO_WORKING_COPY,
NO_COMMIT,
UNCATEGORIZED_ERROR,
)

Expand Down Expand Up @@ -442,14 +443,18 @@ def diff(ctx, output_format, output_path, exit_code, args):
commit_target = repo.revparse_single(commit_parts[2] or "HEAD")
L.debug("commit_target=%s", commit_target.id)
except KeyError:
raise click.BadParameter("Invalid commit spec", param_hint="commit")
raise NotFound(
"Invalid commit spec", param_hint="commit", exit_code=NO_COMMIT
)
else:
path_list.pop(0)
else:
try:
commit_base = repo.revparse_single(commit_parts[0])
except KeyError:
raise click.BadParameter("Invalid commit spec", param_hint="commit")
raise NotFound(
"Invalid commit spec", param_hint="commit", exit_code=NO_COMMIT
)
else:
path_list.pop(0)

Expand Down
36 changes: 29 additions & 7 deletions sno/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import click

# Exit codes
INVALID_ARGUMENT = 10

SUCCESS = 0
SUCCESS_WITH_FLAG = 1

INVALID_ARGUMENT = 2

# We could use 1 for this, except in --exit-code mode.
# So we always use 11 for consistency.
UNCATEGORIZED_ERROR = 11

INVALID_OPERATION = 20

Expand All @@ -14,12 +22,12 @@
NO_CHANGES = 44
NO_WORKING_COPY = 45
NO_USER = 46
NO_IMPORT_SOURCE = 47
NO_TABLE = 48

SUBPROCESS_ERROR = 50
NO_COMMIT = 47
NO_IMPORT_SOURCE = 48
NO_TABLE = 49

UNCATEGORIZED_ERROR = 99
SUBPROCESS_ERROR_FLAG = 128
DEFAULT_SUBPROCESS_ERROR = 129


class BaseException(click.ClickException):
Expand Down Expand Up @@ -66,4 +74,18 @@ class NotFound(BaseException):


class SubprocessError(BaseException):
exit_code = SUBPROCESS_ERROR
exit_code = DEFAULT_SUBPROCESS_ERROR

def __init__(
self,
message,
exit_code=None,
param=None,
param_hint=None,
called_process_error=None,
):
super(SubprocessError, self).__init__(
message, exit_code=exit_code, param=param, param_hint=param_hint
)
if called_process_error and not exit_code:
self.exit_code = SUBPROCESS_ERROR_FLAG + called_process_error.return_code

0 comments on commit 703ede8

Please sign in to comment.