Skip to content

Commit f1d5f13

Browse files
fmoessbauerjan-kiszka
authored andcommitted
fix: show stderror as well on patching errors
In case patching fails, we need to capture stderror as well, as git emits the reason only on stderr. While fixing this, we parameterize the PatchApplyError to print the vcs data in a uniform format. Fixes: 5e4da50 ("repos: restore error handling of patch apply") Signed-off-by: Felix Moessbauer <[email protected]> Signed-off-by: Jan Kiszka <[email protected]>
1 parent e8e5ea5 commit f1d5f13

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

kas/repos.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ class PatchApplyError(KasUserError):
7272
"""
7373
The provided patch file could not be applied
7474
"""
75+
def __init__(self, msg, cmd=None, out=None, err=None):
76+
if cmd:
77+
msg += '\nvcs command: ' + ' '.join(cmd)
78+
if out and out.strip():
79+
msg += f'\nvcs output:\n{out.strip()}'
80+
if err and err.strip():
81+
msg += f'\nvcs error:\n{err.strip()}'
82+
super().__init__(msg)
7583

7684

7785
class Repo:
@@ -500,24 +508,24 @@ async def apply_patches_async(self):
500508

501509
for (path, patch_id) in my_patches:
502510
cmd = self.apply_patches_file_cmd(path)
503-
(retc, output) = await run_cmd_async(
504-
cmd, cwd=self.path, fail=False)
511+
(retc, out, err) = await run_cmd_async(
512+
cmd, cwd=self.path, fail=False, capture_stderr=True)
505513
if retc:
506514
raise PatchApplyError(
507-
'Could not apply patch. Please fix repos and patches. '
508-
f'(patch path: {path}, repo: {self.name}, patch '
509-
f'entry: {patch_id}, vcs output: {output})')
515+
'Could not apply patch. Please fix repos and patches:\n'
516+
f'patch path: {path}, repo: {self.name}, patch '
517+
f'entry: {patch_id}', cmd, out, err)
510518

511519
logging.info('Patch applied. '
512520
'(patch path: %s, repo: %s, patch entry: %s)',
513521
path, self.name, patch_id)
514522

515523
cmd = self.add_cmd()
516-
(retc, output) = await run_cmd_async(
517-
cmd, cwd=self.path, fail=False)
524+
(retc, out, err) = await run_cmd_async(
525+
cmd, cwd=self.path, fail=False, capture_stderr=True)
518526
if retc:
519-
raise PatchApplyError('Could not add patched files. repo: '
520-
f'{self.name}, vcs output: {output})')
527+
raise PatchApplyError('Could not add patched files: repo: '
528+
f'{self.name}', cmd, out, err)
521529

522530
timestamp = self.get_patch_timestamp(path)
523531
if not timestamp:
@@ -529,11 +537,11 @@ async def apply_patches_async(self):
529537
msg = f'kas: {patch_id}\n\npatch {path} applied by kas'
530538
cmd = self.commit_cmd(env, 'kas <[email protected]>', msg,
531539
timestamp)
532-
(retc, output) = await run_cmd_async(
533-
cmd, cwd=self.path, env=env, fail=False)
540+
(retc, out, err) = await run_cmd_async(
541+
cmd, cwd=self.path, env=env, fail=False, capture_stderr=True)
534542
if retc:
535543
raise PatchApplyError('Could not commit patch changes. repo: '
536-
f'{self.name}, vcs output: {output})')
544+
f'{self.name}', cmd, out, err)
537545

538546
return 0
539547

0 commit comments

Comments
 (0)