Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: python.ts add exception type #21230

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

tomasmatus
Copy link
Member

Add exception type to handle cases when spawned python script exits with error.

@tomasmatus tomasmatus requested a review from jelly November 7, 2024 14:50
Add exception type to handle cases when spawned python script exits with
error.
@tomasmatus
Copy link
Member Author

I'm not really sure if the exit_status can also be null as I would expect any shell to have an exist status but it's probably better to be safe and also assume it can be null.

@tomasmatus
Copy link
Member Author

ok it can be

this.exit_status = null;

Copy link
Member

@jelly jelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to publish


const pyinvoke = ["sh", "-ec", "exec $(command -v /usr/libexec/platform-python || command -v python3) -c \"$@\"", "--"];

export interface PythonExitStatus extends BasicError {
exit_status: number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be null?

    function ProcessError(options, name) {
        this.problem = options.problem || null;
        this.exit_status = options["exit-status"];
        if (this.exit_status === undefined)
            this.exit_status = null;
        this.exit_signal = options["exit-signal"];
        if (this.exit_signal === undefined)
            this.exit_signal = null;
        this.message = options.message;

        if (this.message === undefined) {
            if (this.problem)
                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)
                this.message = cockpit.format(_("$0 exited with code $1"), name, this.exit_status);

Although seems like a bug? We set it to null if undefined and then do !== undefined this is weird

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I have a feeling that it's a bug and instead it should be checking for this.exit_status !== null

`exit_status` won't be undefined as it is set to `null` when checked for
undefined for the first time.
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

@jelly jelly merged commit 6598ea0 into cockpit-project:main Nov 12, 2024
83 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants