Skip to content

Commit

Permalink
werk: improve error reporting
Browse files Browse the repository at this point in the history
show message from git on error instead of traceback

for example

```
% werk pick 79969
error: short object ID 79969 is ambiguous
hint: The candidates are:
hint:   7996935d4dd commit 2022-01-19 - Update notes for submitted changes
hint:   79969f1 commit 2024-06-13 - 16512 FIX Restart scheduler after setting "use the
status of a service"
hint:   79969b974f1 tree
hint:   799697847c0 blob
hint:   79969e8229f blob
fatal: ambiguous argument '79969': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
```

was
```
Traceback (most recent call last):
  File "/home/mlaurin/src/check_mk-230.git/packages/cmk-werks/cmk/werks/cli.py", line 884,
in werk_cherry_pick
    result = subprocess.run(
             ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'diff-tree', '--no-commit-id', '--name-only
', '-r', '79969']' returned non-zero exit status 128.
```

Change-Id: I539641261ad0f7764cebc31376fcd515477fc607
  • Loading branch information
Synss committed Jun 17, 2024
1 parent c578a5f commit 570faf5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/cmk-werks/cmk/werks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,15 @@ class WerkToPick(NamedTuple):

def werk_cherry_pick(commit_id: str, no_commit: bool, werk_version: WerkVersion) -> None:
# First get the werk_id
result = subprocess.run(
["git", "diff-tree", "--no-commit-id", "--name-only", "-r", commit_id],
capture_output=True,
check=True,
)
try:
result = subprocess.run(
["git", "diff-tree", "--no-commit-id", "--name-only", "-r", commit_id],
capture_output=True,
check=True,
)
except subprocess.CalledProcessError as exc:
sys.stderr.buffer.write(exc.stderr)
sys.exit(exc.returncode)
found_werk_path: WerkToPick | None = None
for line in result.stdout.splitlines():
filename = Path(line.decode("utf-8"))
Expand Down

0 comments on commit 570faf5

Please sign in to comment.