Skip to content

Fixes error message display when raising errors from a generator function#2889

Merged
abidlabs merged 1 commit into
gradio-app:mainfrom
JaySmithWpg:generator-error-handling
Dec 27, 2022
Merged

Fixes error message display when raising errors from a generator function#2889
abidlabs merged 1 commit into
gradio-app:mainfrom
JaySmithWpg:generator-error-handling

Conversation

@JaySmithWpg
Copy link
Copy Markdown
Contributor

@JaySmithWpg JaySmithWpg commented Dec 27, 2022

Description

When an error is raised in a function that returns iterative output to Gradio, the error is not correctly displayed in the user interface. The message is never delivered to the browser.

This function correctly displays the modal error message in the browser:

def foo():
    raise gr.Error("Bar") # This will appear in the browser

But if the function is a generator that yields any results before the error is raised, the error message never appears in the browser:

def foo():
    yield {status_text: "It's about to fail"}
    raise gr.Error("Bar") # This will not appear in the browser

Console output, thankfully, is not impacted by this bug.

This happens because Queue.process_events does not check the status of the last message received. It gets the status of the second last message received.

This PR changes Queue's behaviour to check the final message status and use that status to determine which message should be used to communicate the end of the generator to the browser.

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@JaySmithWpg JaySmithWpg force-pushed the generator-error-handling branch from c8d43d9 to 3d62b02 Compare December 27, 2022 06:49
@JaySmithWpg JaySmithWpg marked this pull request as ready for review December 27, 2022 06:50
@abidlabs
Copy link
Copy Markdown
Member

Thanks for this contribution @JaySmithWpg, including the test! Testing it out now

@abidlabs
Copy link
Copy Markdown
Member

LGTM, thanks @JaySmithWpg for fixing this issue in the library 🧡

@abidlabs abidlabs merged commit 571e5eb into gradio-app:main Dec 27, 2022
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.

2 participants