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

[REF-3589] raise EventHandlerArgMismatch when event handler args don't match spec #3853

Merged
merged 5 commits into from
Aug 29, 2024

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Aug 28, 2024

2 new error messages when the event trigger spec does not match the function definiton.

reflex.utils.exceptions.EventHandlerArgMismatch: The number of arguments accepted by State.no_arg (0) does not match the arguments passed by the event trigger: ['form_data']
See https://reflex.dev/docs/events/event-arguments/
reflex.utils.exceptions.EventFnArgMismatch: The number of arguments accepted by <function index.<locals>.<lambda> at 0x10c791ee0> (0) does not match the arguments passed by the event trigger: ['form_data']
See https://reflex.dev/docs/events/event-arguments/

masenf added 4 commits August 28, 2024 14:20
Add test cases for event triggers defined as annotations.

Add additional cases around lambda returning different values.

Improve assertions for invalid tests (each line needs its own `pytest.raises`).

More invalid test cases.
…t match spec

Improve error message for common issue.

Previously when the event handler arguments didn't match the spec, the
traceback resulted in:

```
OSError: could not get source code
```

Now this problem is traceable as a distinct error condition and users are
empowered to debug their code and reference the documentation (to be updated)
for further information.
Improve error message for another common issue encountered in the reflex framework.

Previous error message was

```
TypeError: index.<locals>.<lambda>() takes 0 positional arguments but 1 was given
```
@masenf
Copy link
Collaborator Author

masenf commented Aug 28, 2024

Need to strip one argument off the count when the event fn is a bound method / partial, etc.

@masenf masenf merged commit 356deb5 into main Aug 29, 2024
46 checks passed
@masenf masenf deleted the masenf/event-arg-handling branch August 29, 2024 23:05
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