Skip to content

Commit

Permalink
refactor message formatting when there is GitCommandError
Browse files Browse the repository at this point in the history
  • Loading branch information
suvayu committed Mar 28, 2024
1 parent 0d4ac5e commit d8429d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions orchestra/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import IntEnum
import sys

from git import GitCommandError


class ErrorCodes(IntEnum):
CONFIG_ERR = 1
Expand Down Expand Up @@ -29,3 +31,7 @@ def format_exc(exc: Exception, notes: str = "") -> str:
if trailer:
err += f"\n\n[bold]{trailer}"
return err


def format_git_cmd_err(exc: GitCommandError) -> str:
return f"Git command: {exc.command!r} failed with {exc.status=}\n{exc.stderr}"
5 changes: 2 additions & 3 deletions orchestra/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rich.console import Console
from rich.prompt import Prompt

from orchestra import ErrorCodes
from orchestra import ErrorCodes, format_git_cmd_err
from orchestra.config import CONF
from orchestra.release import remote_name

Expand All @@ -22,8 +22,7 @@ def git_error_handler(res: PushInfoList, err: ErrorCodes, msg: str):
res.raise_if_error()
except GitCommandError as exc:
console.print(f"pushing {msg} failed!")
console.print(f"Git command: {exc.command!r} failed with {exc.status=}")
console.print(exc.stderr)
console.print(format_git_cmd_err(exc))
err.exit()
else:
console.print(f"pushed {msg}")
Expand Down

0 comments on commit d8429d0

Please sign in to comment.