From 3e4165fc6d948cdd283528a2da5d91dca944f777 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:47:06 +0200 Subject: [PATCH] use the shared error helper for Docker commands Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- src/main.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index bac0626..598e63c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,8 +28,8 @@ actionsToolkit.run( await Docker.getExecOutput(['image', 'inspect', input.image], { ignoreReturnCode: true }).then(res => { - if (res.stderr.length > 0 && res.exitCode != 0) { - throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'); + if (res.exitCode != 0) { + throw new Error(`Failed to inspect image ${input.image}: ${Docker.getErrorMessage(res.stderr)}`); } }); }); @@ -38,8 +38,8 @@ actionsToolkit.run( await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--version'], { ignoreReturnCode: true }).then(res => { - if (res.stderr.length > 0 && res.exitCode != 0) { - throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'); + if (res.exitCode != 0) { + throw new Error(`Failed to get binfmt version: ${Docker.getErrorMessage(res.stderr)}`); } }); }); @@ -49,8 +49,8 @@ actionsToolkit.run( await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--uninstall', 'qemu-*'], { ignoreReturnCode: true }).then(res => { - if (res.stderr.length > 0 && res.exitCode != 0) { - throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'); + if (res.exitCode != 0) { + throw new Error(`Failed to uninstall current emulators: ${Docker.getErrorMessage(res.stderr)}`); } }); }); @@ -60,8 +60,8 @@ actionsToolkit.run( await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--install', input.platforms], { ignoreReturnCode: true }).then(res => { - if (res.stderr.length > 0 && res.exitCode != 0) { - throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'); + if (res.exitCode != 0) { + throw new Error(`Failed to install QEMU static binaries: ${Docker.getErrorMessage(res.stderr)}`); } }); }); @@ -71,8 +71,8 @@ actionsToolkit.run( ignoreReturnCode: true, silent: true }).then(res => { - if (res.stderr.length > 0 && res.exitCode != 0) { - throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'); + if (res.exitCode != 0) { + throw new Error(`Failed to extract available platforms: ${Docker.getErrorMessage(res.stderr)}`); } const platforms: Platforms = JSON.parse(res.stdout.trim()); core.info(`${platforms.supported.join(',')}`);