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

Improve error messages for context managers called functionally #1008

Open
gadenbuie opened this issue Jan 16, 2024 · 0 comments
Open

Improve error messages for context managers called functionally #1008

gadenbuie opened this issue Jan 16, 2024 · 0 comments
Labels

Comments

@gadenbuie
Copy link
Collaborator

Users who see existing documentation or examples using shiny.ui.card() may try the following app structure

from shiny.express import ui

a_card = ui.card("A simple card")

but this will fail with a TypeError

[...snip...]

  File "/Users/garrick/work/posit-dev/py-shiny/shiny/express/app.py", line 14, in __getattr__
    return wrap_express_app(Path(name))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/garrick/work/posit-dev/py-shiny/shiny/express/_run.py", line 42, in wrap_express_app
    app_ui = run_express(file).tagify()
             ^^^^^^^^^^^^^^^^^
  File "/Users/garrick/work/posit-dev/py-shiny/shiny/express/_run.py", line 98, in run_express
    exec(
  File "/Users/garrick/work/posit-dev/py-shiny/shiny/api-examples/layout_column_wrap/app-express.py", line 3, in <module>
    a_card = ui.card("A simple card")
             ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: card() takes 0 positional arguments but 1 was given

This generic error is not very helpful for new users and does not provide actionable advice. Ideally, we'd instruct users to switch to the context manager form, possibly with an error like the following:

`card()` was called with positional arguments, but in Shiny Express `card()`
does not take unnamed arguments. Please use the `with ui.card():` form instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant