Skip to content

Commit

Permalink
lib: Make ProcessError accessible to TypeScript code
Browse files Browse the repository at this point in the history
So that we can do "if (err instanceof cockpit.ProcessError)" in catch
clauses.
  • Loading branch information
mvollmer committed Dec 20, 2024
1 parent 3b9e6cc commit af2a6d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/lib/cockpit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ declare module 'cockpit' {

/* === cockpit.{spawn,script} ============================= */

class ProcessError {
problem: string | null;
exit_status: number | null;
exit_signal: number | null;
message: string;
}

interface Spawn<T> extends DeferredPromise<T> {
input(message?: T | null, stream?: boolean): DeferredPromise<T>;
stream(callback: (data: T) => void): DeferredPromise<T>;
Expand Down
2 changes: 2 additions & 0 deletions pkg/lib/cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,8 @@ function factory() {
};
}

cockpit.ProcessError = ProcessError;

function spawn_debug() {
if (window.debugging == "all" || window.debugging?.includes("spawn"))
console.debug.apply(console, arguments);
Expand Down

0 comments on commit af2a6d6

Please sign in to comment.