@@ -294,34 +294,30 @@ class FlutterWebConnection {
294
294
295
295
/// Sends command via WebDriver to Flutter web application.
296
296
Future <dynamic > sendCommand (String script, Duration ? duration) async {
297
- dynamic result ;
297
+ String phase = 'executing' ;
298
298
try {
299
+ // Execute the script, which should leave the result in the `$flutterDriverResult` global variable.
299
300
await _driver.execute (script, < void > []);
300
- } catch (error) {
301
- // We should not just arbitrarily throw all exceptions on the ground.
302
- // This is probably hiding real errors.
303
- // TODO(ianh): Determine what exceptions are expected here and handle those specifically.
304
- }
305
301
306
- try {
307
- result = await waitFor <dynamic >(
302
+ // Read the result.
303
+ phase = 'reading' ;
304
+ final dynamic result = await waitFor <dynamic >(
308
305
() => _driver.execute (r'return $flutterDriverResult' , < String > []),
309
306
matcher: isNotNull,
310
307
timeout: duration ?? const Duration (days: 30 ),
311
308
);
312
- } catch (error) {
313
- // We should not just arbitrarily throw all exceptions on the ground .
314
- // This is probably hiding real errors.
315
- // TODO(ianh): Determine what exceptions are expected here and handle those specifically.
316
- // Returns null if exception thrown.
317
- return null ;
318
- } finally {
319
- // Resets the result.
320
- await _driver. execute ( r'''
321
- $flutterDriverResult = null
322
- ''' , < void > [] );
309
+
310
+ // Reset the result to null to avoid polluting the results of future commands .
311
+ phase = 'resetting' ;
312
+ await _driver. execute ( r'$flutterDriverResult = null' , < void > []);
313
+ return result;
314
+ } catch (error, stackTrace) {
315
+ throw DriverError (
316
+ 'Error while $ phase FlutterDriver result for command: $ script ' ,
317
+ error,
318
+ stackTrace,
319
+ );
323
320
}
324
- return result;
325
321
}
326
322
327
323
/// Gets performance log from WebDriver.
0 commit comments