Skip to content

Commit 21b9750

Browse files
authored
[web] do not swallow WebDriver errors (#103754)
1 parent fe87538 commit 21b9750

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

packages/flutter_driver/lib/src/driver/web_driver.dart

+16-20
Original file line numberDiff line numberDiff line change
@@ -294,34 +294,30 @@ class FlutterWebConnection {
294294

295295
/// Sends command via WebDriver to Flutter web application.
296296
Future<dynamic> sendCommand(String script, Duration? duration) async {
297-
dynamic result;
297+
String phase = 'executing';
298298
try {
299+
// Execute the script, which should leave the result in the `$flutterDriverResult` global variable.
299300
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-
}
305301

306-
try {
307-
result = await waitFor<dynamic>(
302+
// Read the result.
303+
phase = 'reading';
304+
final dynamic result = await waitFor<dynamic>(
308305
() => _driver.execute(r'return $flutterDriverResult', <String>[]),
309306
matcher: isNotNull,
310307
timeout: duration ?? const Duration(days: 30),
311308
);
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+
);
323320
}
324-
return result;
325321
}
326322

327323
/// Gets performance log from WebDriver.

0 commit comments

Comments
 (0)