From 21b975041fd06990348c73d392464eece93ae65b Mon Sep 17 00:00:00 2001 From: Yegor Date: Mon, 16 May 2022 13:44:24 -0700 Subject: [PATCH] [web] do not swallow WebDriver errors (#103754) --- .../lib/src/driver/web_driver.dart | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/flutter_driver/lib/src/driver/web_driver.dart b/packages/flutter_driver/lib/src/driver/web_driver.dart index 4871f28ff6..569b28e2a2 100644 --- a/packages/flutter_driver/lib/src/driver/web_driver.dart +++ b/packages/flutter_driver/lib/src/driver/web_driver.dart @@ -294,34 +294,30 @@ class FlutterWebConnection { /// Sends command via WebDriver to Flutter web application. Future sendCommand(String script, Duration? duration) async { - dynamic result; + String phase = 'executing'; try { + // Execute the script, which should leave the result in the `$flutterDriverResult` global variable. await _driver.execute(script, []); - } catch (error) { - // We should not just arbitrarily throw all exceptions on the ground. - // This is probably hiding real errors. - // TODO(ianh): Determine what exceptions are expected here and handle those specifically. - } - try { - result = await waitFor( + // Read the result. + phase = 'reading'; + final dynamic result = await waitFor( () => _driver.execute(r'return $flutterDriverResult', []), matcher: isNotNull, timeout: duration ?? const Duration(days: 30), ); - } catch (error) { - // We should not just arbitrarily throw all exceptions on the ground. - // This is probably hiding real errors. - // TODO(ianh): Determine what exceptions are expected here and handle those specifically. - // Returns null if exception thrown. - return null; - } finally { - // Resets the result. - await _driver.execute(r''' - $flutterDriverResult = null - ''', []); + + // Reset the result to null to avoid polluting the results of future commands. + phase = 'resetting'; + await _driver.execute(r'$flutterDriverResult = null', []); + return result; + } catch (error, stackTrace) { + throw DriverError( + 'Error while $phase FlutterDriver result for command: $script', + error, + stackTrace, + ); } - return result; } /// Gets performance log from WebDriver.