Better error message when passing global callbacks to Gui and Gui.run#2837
Conversation
Fixes Avaiga#2764 - Gui.__init__() now raises a clear TypeError with guidance when global callback names (on_change, on_init, on_navigate, etc.) are passed as keyword arguments, directing users to assign them as attributes instead. - Gui.run() now emits a warning when global callback names are passed, since they were previously silently ignored. - Added unit tests for both behaviors.
|
Thanks a lot @Krishnachaitanyakc for your contribution. However I'm reluctant to let this go through. The reason is this 'problem' is very, very generic. Implementing this guard rail in these two methods ( Please let me sort this out with @arcanaxion, who originally created the issue you're fixing. What do you think? Thanks again |
|
Thanks you for your input, @arcanaxion. Yes, your point is completely correct: why check here and not elsewhere? What do you think? What about you @Krishnachaitanyakc? |

Summary
Fixes #2764
Gui.__init__(): Now raises a clearTypeErrorwith actionable guidance when users mistakenly pass global callback names (on_change,on_init,on_navigate,on_action,on_exception,on_status,on_page_load,on_user_content) as keyword arguments. The error message directs users to assign them as attributes on the Gui instance instead (e.g.,gui.on_change = handle_change).Gui.run(): Now emits a warning when global callback names are passed as keyword arguments, since they were previously silently ignored due to not being recognized config keys. The warning provides the same actionable guidance.Gui.__init__()also produce a clearTypeErrorinstead of being silently accepted.Before
After
Test plan
test_init_rejects_global_callback_with_helpful_message- verifies single callback in__init__test_init_rejects_multiple_global_callbacks_with_helpful_message- verifies multiple callbacks in__init__test_init_rejects_unknown_kwargs- verifies unknown kwargs still raiseTypeErrortest_run_warns_on_global_callback_kwargs- verifies warning inrun()Gui()construction is unaffected)