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

Fix: Dispatched errors from inside components bubble to top #4786

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -144,6 +144,7 @@ def start_process(name):
- Ensure code is correctly formatted and copy button is always present in Chatbot by [@pngwn](https://github.com/pngwn) in [PR 4527](https://github.com/gradio-app/gradio/pull/4527)
- `show_label` will not automatically be set to `True` in `gr.BarPlot.update` by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4531](https://github.com/gradio-app/gradio/pull/4531)
- `gr.BarPlot` group text now respects darkmode by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4531](https://github.com/gradio-app/gradio/pull/4531)
- Fix dispatched errors from within components [@aliabid94](https://github.com/aliabid94) in [PR 4786](https://github.com/gradio-app/gradio/pull/4786)

## Other Changes:

Expand Down
14 changes: 14 additions & 0 deletions js/app/src/Blocks.svelte
Expand Up @@ -371,6 +371,7 @@
const is_external_url = (link: string | null) =>
link && new URL(link, location.href).origin !== location.origin;

let attached_error_listeners: number[] = [];
async function handle_mount() {
await tick();

Expand Down Expand Up @@ -417,6 +418,19 @@
handled_dependencies[i].push(id);
});
});
components.forEach((c) => {
if (!attached_error_listeners.includes(c.id)) {
if (c.instance) {
attached_error_listeners.push(c.id);
c.instance.$on("error", (event_data: any) => {
messages = [
new_message(event_data.detail, -1, "error"),
...messages
];
});
}
}
});
}

function handle_destroy(id: number) {
Expand Down
2 changes: 1 addition & 1 deletion js/app/src/components/Audio/Audio.svelte
Expand Up @@ -88,7 +88,7 @@
on:error={({ detail }) => {
loading_status = loading_status || {};
loading_status.status = "error";
loading_status.message = detail;
dispatch("error", detail);
}}
>
<UploadText type="audio" />
Expand Down
3 changes: 2 additions & 1 deletion js/app/src/components/Image/Image.svelte
Expand Up @@ -31,6 +31,7 @@

const dispatch = createEventDispatcher<{
change: undefined;
error: string;
}>();

$: value, dispatch("change");
Expand Down Expand Up @@ -78,7 +79,7 @@
on:error={({ detail }) => {
loading_status = loading_status || {};
loading_status.status = "error";
loading_status.message = detail;
dispatch("error", detail)
}}
{label}
{show_label}
Expand Down