Repository navigation
fix: never crash invoke handlers on nil or missing args - #52
Merged
AdamMusa merged 1 commit intoNov 2, 2026
Merged
Conversation
Ruby's Page#invoke sends args: nil for methods called without arguments, and handlers indexed args[...] unconditionally, so calls such as page_view.next_page or audio.play failed on the client. Control.invokeMethod now always hands listeners a map (new invokeArgs helper). Handlers that still crashed on a missing key now either use a meaningful default (SharedPreferences get_keys prefix, Tabs move_to, SearchBar close_view, View confirm_pop, device orientations, Tester finder_index) or, when the argument is genuinely required, throw a clear ArgumentError via requireInvokeArg (e.g. 'SecureStorage.set requires a "value" argument'), which the backend returns to Ruby as the invoke error instead of a cryptic null-check failure or a silent success. Tester without a harness raises a StateError instead of passing. Covers Tabs, SearchBar, Screenshot, View, Page, the Clipboard, FilePicker, ScreenBrightness, SemanticsService, Share, SharedPreferences, Tester and UrlLauncher services, and the SecureStorage, WebView, Geolocator and Camera extensions.
AdamMusa
force-pushed
the
fix/invoke-handler-null-args
branch
from
October 28, 2026 22:38
07e1902 to
5f65898
Compare
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Engine-only fix. No Ruby change is needed.
Revised after QA review: genuinely required arguments now return a clear error reply instead of a silent no-op. Meaningful defaults are kept. This follows QA's 32-site classification in
qa-reviews.md(engine#52).Problem
Ruby's
Page#invokesends"args" => nilwhenever a method is called without arguments, for exampleaudio.play,page_view.next_page,interactive_viewer.resetorsearch_bar.open_view. Most Dart invoke handlers indexedargs[...]unconditionally, so these calls threwNoSuchMethodErroron the client. Several handlers also failed with cryptic errors when a key was missing, even with a map payload:args["key"]!in SharedPreferences, SecureStorage and UrlLauncheras int/as Listin Cupertino Tabs and Clipboardargs["rtl"] ? ...in SemanticsServiceCompleter<bool>.complete(null)in Viewconfirm_popint→double?and non-nullString/boolparameters in Screenshot, Tester, FilePicker, WebView and GeolocatorFix
Control.invokeMethodnormalizes args with the newinvokeArgs()(utils/invoke.dart, exported). Every listener in core and in every extension now always receives aMap.requireInvokeArg(args, "key", "SecureStorage.set")throwsArgumentError('SecureStorage.set requires a "key" argument'). The backend already returns a thrown handler error as the invokeerror(ruflet_backend.dart_onInvokeMethod), so Ruby raises it (sync) or gets it inon_result(async). A missing required value can no longer look like success, andget(nil)can no longer look like "not found".skipInvokeis now used only for Tabsmove_towithout an index.set/get/contains_key/removekey;valueforset). A null value would make flutter_secure_storage delete the key, so it never reaches the platform.set/get/contains_key/removekey;valueforset), raised before touching the pluginget_keysset/set_image/set_filesdata/files; a non-listfilesis an error too)share_text/share_uri/share_filestext/uri/files; an empty file list is an error too)launch_url/can_launch_url/open_windowurl; a non-string url is an error too)announce_message/announce_tooltipmessage);rtldefaults to falseset_*value), with a clearer message than the oldArgumentError.notNullsave_filesrc_byteson web/mobile,file_nameon web)allow_multiple→ false;uploadwith nothing to upload → no-oppush_routeroute)set_allowed_device_orientationsconfirm_popfalse, keep the view (aCompleter<bool>cannot take null)load_file/load_htmlpath/value)initializedescription)find_by_*,take_screenshot,tap,tap_at,long_press,enter_text,mouse_hoverStateError, so a broken test script cannot pass silentlypump/pump_and_settleduration;finder_index→ 0move_to(Material and Cupertino)close_viewcapturepixel_ratioparsed as a double (an int used to throw)distance_betweenEvery other handler is safe once args is a map, because each uses null-safe
parse*helpers or optional parameters:Unknown method names still throw. Two pre-existing
use_super_parametersinfos inruflet_webvieware also fixed.Tests
packages/ruflet/test/widgets/invoke_handler_null_args_test.dart(42 tests):Control.invokeMethod: hands listeners{}fornulland for a non-map, and passes maps through.nulland with{}. None throws, and each optional argument falls back to its default (Tabs, PageView, Column, InteractiveViewer, ContextMenu, SearchBar, Canvas, Dismissible, focus methods, Page orientations, Viewconfirm_pop).nullor{}payload gives anArgumentErrorwith the exact message"<Service>.<method> requires a "<arg>" argument". Missingvalueinset, non-list Clipboard files, an empty Share file list and a non-string url each give a clear error. Pagepush_routegives an error.get_keyswith no prefix returns all keys, FilePickeruploadreturns nil, and Testerpump/pump_and_settle/teardownsucceed with a harness attached.StateError("Tester.<method> requires a running test harness").RufletBackendChannelruns the backend's own dispatch, so the test sees exactly what Ruby receives:SharedPreferences.setwithargs: nil→ reply{result: nil, error: "...SharedPreferences.set requires a "key" argument"}.get_keyswith nil →{result: ["a"], error: nil}.PageView.next_pagewith nil → no error, and the page turns.packages/ruflet_secure_storage/test/secure_storage_test.dart(new, 2 tests; the method channel is mocked):key, orsetwithoutvalue, no platform call is made: nowriteand nodelete.setcoercing5to"5";get_allneeds no args.verify_pr.shwithEXT_PKGS="ruflet_secure_storage ruflet_webview ruflet_geolocator ruflet_camera":Not changed here
Invokes that no handler claims (Window on mobile/web, iOS ContextMenu
open) are fixed generically by #59.