From 4e7a000541fd43a40f02ff94f8692dd0415a2428 Mon Sep 17 00:00:00 2001 From: tomasmatus Date: Thu, 7 Nov 2024 14:31:11 +0100 Subject: [PATCH 1/2] lib: python.ts add exception type Add exception type to handle cases when spawned python script exits with error. --- pkg/lib/python.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/lib/python.ts b/pkg/lib/python.ts index 12c420351f54..a2c72977fb0a 100644 --- a/pkg/lib/python.ts +++ b/pkg/lib/python.ts @@ -17,10 +17,15 @@ * along with Cockpit; If not, see . */ -import cockpit from "cockpit"; +import cockpit, { BasicError } from "cockpit"; const pyinvoke = ["sh", "-ec", "exec $(command -v /usr/libexec/platform-python || command -v python3) -c \"$@\"", "--"]; +export interface PythonExitStatus extends BasicError { + exit_status: number | null, + exit_signal: number | null, +} + // only declare the string variant for the time being; we don't use the binary variant export function spawn ( script_pieces: string | string[], From 5e43e5bce92e5e69c6330c89c2460bcdbd097230 Mon Sep 17 00:00:00 2001 From: tomasmatus Date: Tue, 12 Nov 2024 12:56:04 +0100 Subject: [PATCH 2/2] lib: check for null instead of undefined `exit_status` won't be undefined as it is set to `null` when checked for undefined for the first time. --- pkg/lib/cockpit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/lib/cockpit.js b/pkg/lib/cockpit.js index a529fe060e56..19b88a6e597c 100644 --- a/pkg/lib/cockpit.js +++ b/pkg/lib/cockpit.js @@ -1407,7 +1407,7 @@ function factory() { this.message = cockpit.message(options.problem); else if (this.exit_signal !== null) this.message = cockpit.format(_("$0 killed with signal $1"), name, this.exit_signal); - else if (this.exit_status !== undefined) + else if (this.exit_status !== null) this.message = cockpit.format(_("$0 exited with code $1"), name, this.exit_status); else this.message = cockpit.format(_("$0 failed"), name);