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 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart';
import 'package:meta/meta.dart';
......@@ -27,9 +25,9 @@ class Config {
/// home directory.
factory Config(
String name, {
@required FileSystem fileSystem,
@required Logger logger,
@required Platform platform,
required FileSystem fileSystem,
required Logger logger,
required Platform platform,
}) {
final String filePath = _configPath(platform, fileSystem, name);
final File file = fileSystem.file(filePath);
......@@ -43,8 +41,8 @@ class Config {
/// Defaults to [BufferLogger], [MemoryFileSystem], and [name]=test.
factory Config.test({
String name = 'test',
Directory directory,
Logger logger,
Directory? directory,
Logger? logger,
}) {
directory ??= MemoryFileSystem.test().directory('/');
return Config.createForTesting(directory.childFile('.${kConfigDir}_$name'), logger ?? BufferLogger.test());
......@@ -58,7 +56,7 @@ class Config {
}
try {
ErrorHandlingFileSystem.noExitOnFailure(() {
_values = castStringKeyedMap(json.decode(_file.readAsStringSync()));
_values = castStringKeyedMap(json.decode(_file.readAsStringSync())) ?? <String, dynamic>{};
});
} on FormatException {
_logger
......
......@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../base/error_handling_io.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
......@@ -13,8 +9,8 @@ import '../base/logger.dart';
/// A service for creating and parsing [Depfile]s.
class DepfileService {
DepfileService({
@required Logger logger,
@required FileSystem fileSystem,
required Logger logger,
required FileSystem fileSystem,
}) : _logger = logger,
_fileSystem = fileSystem;
......@@ -67,7 +63,7 @@ class DepfileService {
if (rawUri.trim().isEmpty) {
continue;
}
final Uri fileUri = Uri.tryParse(rawUri);
final Uri? fileUri = Uri.tryParse(rawUri);
if (fileUri == null) {
continue;
}
......@@ -102,7 +98,7 @@ class DepfileService {
.replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n')
.split('\n')
// 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)
// 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.
......
......@@ -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/io.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:path/path.dart' as path; // flutter_ignore: package_path_import
import 'package:process/process.dart';
......@@ -955,8 +953,7 @@ void main() {
verify(source.copySync('dest')).called(1);
});
// Uses context for analytics.
testUsingContext('copySync can directly copy bytes if both files can be opened but copySync fails', () {
testWithoutContext('copySync can directly copy bytes if both files can be opened but copySync fails', () {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
final MockFile source = MockFile();
final MockFile dest = MockFile();
......@@ -978,15 +975,9 @@ void main() {
fileSystem.file('source').copySync('dest');
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.
testUsingContext('copySync deletes the result file if the fallback fails', () {
testWithoutContext('copySync deletes the result file if the fallback fails', () {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
final MockFile source = MockFile();
final MockFile dest = MockFile();
......@@ -1015,8 +1006,6 @@ void main() {
expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit());
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