forked from firka/flutter
catch parse error from corrupt config (#45319)
This commit is contained in:
@@ -3,15 +3,28 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../convert.dart';
|
||||
import '../globals.dart';
|
||||
import 'context.dart';
|
||||
import 'file_system.dart';
|
||||
import 'logger.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
class Config {
|
||||
Config([File configFile]) {
|
||||
Config([File configFile, Logger localLogger]) {
|
||||
final Logger loggerInstance = localLogger ?? logger;
|
||||
_configFile = configFile ?? fs.file(fs.path.join(userHomePath(), '.flutter_settings'));
|
||||
if (_configFile.existsSync()) {
|
||||
_values = castStringKeyedMap(json.decode(_configFile.readAsStringSync()));
|
||||
try {
|
||||
_values = castStringKeyedMap(json.decode(_configFile.readAsStringSync()));
|
||||
} on FormatException {
|
||||
loggerInstance
|
||||
..printError('Failed to decode preferences in ${_configFile.path}.')
|
||||
..printError(
|
||||
'You may need to reapply any previously saved configuration '
|
||||
'with the "flutter config" command.',
|
||||
);
|
||||
_configFile.deleteSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user