Change all instance of throwing strings to throw specific error classes. (#97325)

This commit is contained in:
Lau Ching Jun
2022-02-02 10:45:18 -08:00
committed by GitHub
parent 97124d7bf9
commit d7688ca093
32 changed files with 145 additions and 119 deletions

View File

@@ -153,7 +153,7 @@ void testUsingContext(
print(error); // ignore: avoid_print
print(stackTrace); // ignore: avoid_print
_printBufferedErrors(context);
throw error;
throw error; //ignore: only_throw_errors
});
},
);
@@ -348,10 +348,10 @@ class LocalFileSystemBlockingSetCurrentDirectory extends LocalFileSystem {
@override
set currentDirectory(dynamic value) {
throw 'globals.fs.currentDirectory should not be set on the local file system during '
throw Exception('globals.fs.currentDirectory should not be set on the local file system during '
'tests as this can cause race conditions with concurrent tests. '
'Consider using a MemoryFileSystem for testing if possible or refactor '
'code to not require setting globals.fs.currentDirectory.';
'code to not require setting globals.fs.currentDirectory.');
}
}

View File

@@ -258,7 +258,8 @@ abstract class FakeProcessManager implements ProcessManager {
_pid += 1;
final FakeCommand fakeCommand = findCommand(command, workingDirectory, environment, encoding);
if (fakeCommand.exception != null) {
throw fakeCommand.exception!;
assert(fakeCommand.exception is Exception || fakeCommand.exception is Error);
throw fakeCommand.exception!; // ignore: only_throw_errors
}
if (fakeCommand.onRun != null) {
fakeCommand.onRun!();

View File

@@ -27,7 +27,7 @@ class TestBuildSystem implements BuildSystem {
final List<BuildResult> _results;
final BuildResult? _singleResult;
final Object? _exception;
final Exception? _exception;
final void Function(Target target, Environment environment)? _onRun;
int _nextResult = 0;