mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Lite: Error handling after initialization (#6005)
* Update WorkerProxy to emit a unified `error` event for any type error and a `run-start` event when `run_file` or `run_code` is called, and update Index.svelte to handle these events * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
584fd97d59
commit
e0ed0642ac
7
.changeset/chatty-laws-drop.md
Normal file
7
.changeset/chatty-laws-drop.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"@gradio/app": minor
|
||||
"@gradio/wasm": minor
|
||||
"gradio": minor
|
||||
---
|
||||
|
||||
feat:Lite: Error handling after initialization
|
@ -98,7 +98,15 @@
|
||||
worker_proxy.addEventListener("progress-update", (event) => {
|
||||
loading_text = (event as CustomEvent).detail + "...";
|
||||
});
|
||||
worker_proxy.addEventListener("initialization-error", (event) => {
|
||||
worker_proxy.addEventListener("run-start", (event) => {
|
||||
status = {
|
||||
message: "",
|
||||
load_status: "pending",
|
||||
status: "sleeping",
|
||||
detail: "SLEEPING"
|
||||
}
|
||||
});
|
||||
worker_proxy.addEventListener("error", (event) => {
|
||||
const error: Error = (event as CustomEvent).detail;
|
||||
|
||||
// XXX: Although `status` is expected to store Space status info,
|
||||
|
@ -57,7 +57,7 @@ export class WorkerProxy extends EventTarget {
|
||||
error
|
||||
);
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("initialization-error", {
|
||||
new CustomEvent("error", {
|
||||
detail: error
|
||||
})
|
||||
);
|
||||
@ -65,23 +65,43 @@ export class WorkerProxy extends EventTarget {
|
||||
}
|
||||
|
||||
public async runPythonCode(code: string): Promise<void> {
|
||||
await this.postMessageAsync({
|
||||
type: "run-python-code",
|
||||
data: {
|
||||
code
|
||||
}
|
||||
});
|
||||
this.firstRunPromiseDelegate.resolve();
|
||||
this.dispatchEvent(new Event("run-start"));
|
||||
try {
|
||||
await this.postMessageAsync({
|
||||
type: "run-python-code",
|
||||
data: {
|
||||
code
|
||||
}
|
||||
});
|
||||
this.firstRunPromiseDelegate.resolve();
|
||||
} catch (error) {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("error", {
|
||||
detail: error
|
||||
})
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public async runPythonFile(path: string): Promise<void> {
|
||||
await this.postMessageAsync({
|
||||
type: "run-python-file",
|
||||
data: {
|
||||
path
|
||||
}
|
||||
});
|
||||
this.firstRunPromiseDelegate.resolve();
|
||||
this.dispatchEvent(new Event("run-start"));
|
||||
try {
|
||||
await this.postMessageAsync({
|
||||
type: "run-python-file",
|
||||
data: {
|
||||
path
|
||||
}
|
||||
});
|
||||
this.firstRunPromiseDelegate.resolve();
|
||||
} catch (error) {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("error", {
|
||||
detail: error
|
||||
})
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// A wrapper for this.worker.postMessage(). Unlike that function, which
|
||||
@ -186,6 +206,13 @@ export class WorkerProxy extends EventTarget {
|
||||
data,
|
||||
opts
|
||||
}
|
||||
}).catch((error) => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("error", {
|
||||
detail: error
|
||||
})
|
||||
);
|
||||
throw error;
|
||||
}) as Promise<void>;
|
||||
}
|
||||
|
||||
@ -196,6 +223,13 @@ export class WorkerProxy extends EventTarget {
|
||||
oldPath,
|
||||
newPath
|
||||
}
|
||||
}).catch((error) => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("error", {
|
||||
detail: error
|
||||
})
|
||||
);
|
||||
throw error;
|
||||
}) as Promise<void>;
|
||||
}
|
||||
|
||||
@ -205,6 +239,13 @@ export class WorkerProxy extends EventTarget {
|
||||
data: {
|
||||
path
|
||||
}
|
||||
}).catch((error) => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("error", {
|
||||
detail: error
|
||||
})
|
||||
);
|
||||
throw error;
|
||||
}) as Promise<void>;
|
||||
}
|
||||
|
||||
@ -214,6 +255,13 @@ export class WorkerProxy extends EventTarget {
|
||||
data: {
|
||||
requirements
|
||||
}
|
||||
}).catch((error) => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("error", {
|
||||
detail: error
|
||||
})
|
||||
);
|
||||
throw error;
|
||||
}) as Promise<void>;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user