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

Inaccurate error message in ui.image when file does not exist #3162

Merged

Conversation

CrystalWindSnake
Copy link
Contributor

When using ui.image, if the parameter is a non-existent file path, the following error message will appear in the backend. It is difficult to determine the exact source of the error. This PR fixes this .

from nicegui import ui
from pathlib import Path

missing_path = Path('missing.png')
ui.image(missing_path)

error(not contain useful information to locate the source of the error):

TypeError: Type is not JSON serializable: WindowsPath

@falkoschindler falkoschindler added the enhancement New feature or request label Jun 2, 2024
@falkoschindler falkoschindler added this to the 1.4.27 milestone Jun 2, 2024
@falkoschindler falkoschindler self-requested a review June 2, 2024 10:52
Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request, @CrystalWindSnake! The previous error message was indeed not very helpful.
I moved the check from ImageElement into the SourceElement mixin to make it effective for many more UI elements like ui.audio, ui.video etc.:

ui.audio(Path('foo.mp3'))

@falkoschindler falkoschindler merged commit 2e00244 into zauberzeug:main Jun 2, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants