fix: return futures from virtual device and network session APIs - #174
Merged
Conversation
`MethodChannelMidiCommand` discarded the pigeon call for
`addVirtualDevice`, `removeVirtualDevice` and `setNetworkSessionEnabled`
with `unawaited`, so a platform failure such as
PlatformException(AUDIOERROR, Error -2 while create MIDI virtual source)
escaped as an unhandled asynchronous error. A try/catch around the call
could not see it because the future was dropped inside the platform
implementation.
The three APIs now return `Future<void>` all the way from `MidiCommand`
through `MidiCommandPlatform` to the host API, so callers can await them
and handle failures. Calls that ignore the result keep compiling; custom
platform implementations must widen these overrides from `void`.
The example app now awaits `addVirtualDevice` and reverts its virtual
transport toggle when creation fails.
Fixes #173
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes #173.
Problem
MethodChannelMidiCommanddropped the pigeon call withunawaited, so a platform failure escaped as an unhandled asynchronous error:Wrapping the call in
try/catchcould not help, because the future was discarded inside the platform implementation rather than returned to the caller.Fix
addVirtualDevice,removeVirtualDeviceandsetNetworkSessionEnablednow returnFuture<void>end to end —MidiCommand→MidiCommandPlatform→MethodChannelMidiCommand→ host API:setNetworkSessionEnabledhad the identicalunawaiteddefect one line below the two named in the issue; including it here keeps this to a single breaking-signature change rather than two.Updated in the same shape: the platform-interface base class, and the web, windows and linux implementations. Web now throws asynchronously via
asyncso its "unsupported" error arrives through the future rather than synchronously.Compatibility
midi.addVirtualDevice(name: 'x');is still a valid statement).MidiCommandPlatformimplementations: the three overrides must widen fromvoidtoFuture<void>. Documented as migration item 7 in the README.Verification
test/flutter_midi_command_test.dartasserting a platform error reaches aMidiCommandcaller, plus a success-path test.PlatformExceptionpropagates out ofMethodChannelMidiCommand.addVirtualDeviceand reverts its virtual transport toggle when creation fails — previously it silently kept the toggle on.flutter analyzeclean; root, platform-interface, linux, windows, web (chrome) and example suites pass.