Unverified Commit 5cef69dd authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] add a gradle error handler for could not open cache directory (#129222)

Works around part of https://github.com/flutter/flutter/issues/128866
parent d2c4b5a1
...@@ -83,6 +83,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[ ...@@ -83,6 +83,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
zipExceptionHandler, zipExceptionHandler,
incompatibleJavaAndGradleVersionsHandler, incompatibleJavaAndGradleVersionsHandler,
remoteTerminatedHandshakeHandler, remoteTerminatedHandshakeHandler,
couldNotOpenCacheDirectoryHandler,
]; ];
const String _boxTitle = 'Flutter Fix'; const String _boxTitle = 'Flutter Fix';
...@@ -715,3 +716,22 @@ final GradleHandledError remoteTerminatedHandshakeHandler = GradleHandledError( ...@@ -715,3 +716,22 @@ final GradleHandledError remoteTerminatedHandshakeHandler = GradleHandledError(
}, },
eventLabel: 'remote-terminated-handshake', eventLabel: 'remote-terminated-handshake',
); );
@visibleForTesting
final GradleHandledError couldNotOpenCacheDirectoryHandler = GradleHandledError(
test: (String line) => line.contains('> Could not open cache directory '),
handler: ({
required String line,
required FlutterProject project,
required bool usesAndroidX,
required bool multidexEnabled,
}) async {
globals.printError(
'${globals.logger.terminal.warningMark} '
'Gradle threw an error while resolving dependencies.'
);
return GradleBuildStatus.retry;
},
eventLabel: 'could-not-open-cache-directory',
);
...@@ -51,6 +51,7 @@ void main() { ...@@ -51,6 +51,7 @@ void main() {
zipExceptionHandler, zipExceptionHandler,
incompatibleJavaAndGradleVersionsHandler, incompatibleJavaAndGradleVersionsHandler,
remoteTerminatedHandshakeHandler, remoteTerminatedHandshakeHandler,
couldNotOpenCacheDirectoryHandler,
]) ])
); );
}); });
...@@ -134,6 +135,7 @@ Caused by: java.io.EOFException: SSL peer shut down incorrectly ...@@ -134,6 +135,7 @@ Caused by: java.io.EOFException: SSL peer shut down incorrectly
) )
); );
}); });
testUsingContext('retries if gradle fails downloading with proxy error', () async { testUsingContext('retries if gradle fails downloading with proxy error', () async {
const String errorMessage = r''' const String errorMessage = r'''
Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request" Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
...@@ -627,9 +629,7 @@ Command: /home/android/gradlew assembleRelease ...@@ -627,9 +629,7 @@ Command: /home/android/gradlew assembleRelease
) )
); );
}); });
});
group('permission errors', () {
testUsingContext('pattern', () async { testUsingContext('pattern', () async {
const String errorMessage = ''' const String errorMessage = '''
Permission denied Permission denied
...@@ -1386,6 +1386,32 @@ Could not compile build file '…/example/android/build.gradle'. ...@@ -1386,6 +1386,32 @@ Could not compile build file '…/example/android/build.gradle'.
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
}); });
testUsingContext('couldNotOpenCacheDirectoryHandler', () async {
final GradleBuildStatus status = await couldNotOpenCacheDirectoryHandler.handler(
line: '''
FAILURE: Build failed with an exception.
* Where:
Script '/Volumes/Work/s/w/ir/x/w/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 276
* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin class 'FlutterPlugin'.
> Could not open cache directory 41rl0ui7kgmsyfwn97o2jypl6 (/Volumes/Work/s/w/ir/cache/gradle/caches/6.7/gradle-kotlin-dsl/41rl0ui7kgmsyfwn97o2jypl6).
> Failed to create Jar file /Volumes/Work/s/w/ir/cache/gradle/caches/6.7/generated-gradle-jars/gradle-api-6.7.jar.''',
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
usesAndroidX: true,
multidexEnabled: true,
);
expect(testLogger.errorText, contains('Gradle threw an error while resolving dependencies'));
expect(status, GradleBuildStatus.retry);
}, overrides: <Type, Generator>{
GradleUtils: () => FakeGradleUtils(),
Platform: () => fakePlatform('android'),
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
} }
bool formatTestErrorMessage(String errorMessage, GradleHandledError error) { bool formatTestErrorMessage(String errorMessage, GradleHandledError error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment