Unverified Commit d79b1668 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate error_handling_io to null safety (#78932)

parent 2c413842
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -27,9 +25,9 @@ class Config { ...@@ -27,9 +25,9 @@ class Config {
/// home directory. /// home directory.
factory Config( factory Config(
String name, { String name, {
@required FileSystem fileSystem, required FileSystem fileSystem,
@required Logger logger, required Logger logger,
@required Platform platform, required Platform platform,
}) { }) {
final String filePath = _configPath(platform, fileSystem, name); final String filePath = _configPath(platform, fileSystem, name);
final File file = fileSystem.file(filePath); final File file = fileSystem.file(filePath);
...@@ -43,8 +41,8 @@ class Config { ...@@ -43,8 +41,8 @@ class Config {
/// Defaults to [BufferLogger], [MemoryFileSystem], and [name]=test. /// Defaults to [BufferLogger], [MemoryFileSystem], and [name]=test.
factory Config.test({ factory Config.test({
String name = 'test', String name = 'test',
Directory directory, Directory? directory,
Logger logger, Logger? logger,
}) { }) {
directory ??= MemoryFileSystem.test().directory('/'); directory ??= MemoryFileSystem.test().directory('/');
return Config.createForTesting(directory.childFile('.${kConfigDir}_$name'), logger ?? BufferLogger.test()); return Config.createForTesting(directory.childFile('.${kConfigDir}_$name'), logger ?? BufferLogger.test());
...@@ -58,7 +56,7 @@ class Config { ...@@ -58,7 +56,7 @@ class Config {
} }
try { try {
ErrorHandlingFileSystem.noExitOnFailure(() { ErrorHandlingFileSystem.noExitOnFailure(() {
_values = castStringKeyedMap(json.decode(_file.readAsStringSync())); _values = castStringKeyedMap(json.decode(_file.readAsStringSync())) ?? <String, dynamic>{};
}); });
} on FormatException { } on FormatException {
_logger _logger
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../base/error_handling_io.dart'; import '../base/error_handling_io.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
...@@ -13,8 +9,8 @@ import '../base/logger.dart'; ...@@ -13,8 +9,8 @@ import '../base/logger.dart';
/// A service for creating and parsing [Depfile]s. /// A service for creating and parsing [Depfile]s.
class DepfileService { class DepfileService {
DepfileService({ DepfileService({
@required Logger logger, required Logger logger,
@required FileSystem fileSystem, required FileSystem fileSystem,
}) : _logger = logger, }) : _logger = logger,
_fileSystem = fileSystem; _fileSystem = fileSystem;
...@@ -67,7 +63,7 @@ class DepfileService { ...@@ -67,7 +63,7 @@ class DepfileService {
if (rawUri.trim().isEmpty) { if (rawUri.trim().isEmpty) {
continue; continue;
} }
final Uri fileUri = Uri.tryParse(rawUri); final Uri? fileUri = Uri.tryParse(rawUri);
if (fileUri == null) { if (fileUri == null) {
continue; continue;
} }
...@@ -102,7 +98,7 @@ class DepfileService { ...@@ -102,7 +98,7 @@ class DepfileService {
.replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n') .replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n')
.split('\n') .split('\n')
// Expand escape sequences, so that '\ ', for example,ß becomes ' ' // Expand escape sequences, so that '\ ', for example,ß becomes ' '
.map<String>((String path) => path.replaceAllMapped(_escapeExpr, (Match match) => match.group(1)).trim()) .map<String>((String path) => path.replaceAllMapped(_escapeExpr, (Match match) => match.group(1)!).trim())
.where((String path) => path.isNotEmpty) .where((String path) => path.isNotEmpty)
// The tool doesn't write duplicates to these lists. This call is an attempt to // The tool doesn't write duplicates to these lists. This call is an attempt to
// be resilient to the outputs of other tools which write or user edits to depfiles. // be resilient to the outputs of other tools which write or user edits to depfiles.
......
...@@ -14,8 +14,6 @@ import 'package:flutter_tools/src/base/error_handling_io.dart'; ...@@ -14,8 +14,6 @@ import 'package:flutter_tools/src/base/error_handling_io.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/globals.dart' as globals show flutterUsage;
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:path/path.dart' as path; // flutter_ignore: package_path_import import 'package:path/path.dart' as path; // flutter_ignore: package_path_import
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -955,8 +953,7 @@ void main() { ...@@ -955,8 +953,7 @@ void main() {
verify(source.copySync('dest')).called(1); verify(source.copySync('dest')).called(1);
}); });
// Uses context for analytics. testWithoutContext('copySync can directly copy bytes if both files can be opened but copySync fails', () {
testUsingContext('copySync can directly copy bytes if both files can be opened but copySync fails', () {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test(); final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
final MockFile source = MockFile(); final MockFile source = MockFile();
final MockFile dest = MockFile(); final MockFile dest = MockFile();
...@@ -978,15 +975,9 @@ void main() { ...@@ -978,15 +975,9 @@ void main() {
fileSystem.file('source').copySync('dest'); fileSystem.file('source').copySync('dest');
expect(memoryDest.readAsBytesSync(), expectedBytes); expect(memoryDest.readAsBytesSync(), expectedBytes);
expect((globals.flutterUsage as TestUsage).events, contains(
const TestUsageEvent('error-handling', 'copy-fallback'),
));
}, overrides: <Type, Generator>{
Usage: () => TestUsage(),
}); });
// Uses context for analytics. testWithoutContext('copySync deletes the result file if the fallback fails', () {
testUsingContext('copySync deletes the result file if the fallback fails', () {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test(); final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
final MockFile source = MockFile(); final MockFile source = MockFile();
final MockFile dest = MockFile(); final MockFile dest = MockFile();
...@@ -1015,8 +1006,6 @@ void main() { ...@@ -1015,8 +1006,6 @@ void main() {
expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit()); expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit());
verify(dest.deleteSync(recursive: true)).called(1); verify(dest.deleteSync(recursive: true)).called(1);
}, overrides: <Type, Generator>{
Usage: () => TestUsage(),
}); });
}); });
} }
......
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