Dont crash on malformed packages.json (#45786)

This commit is contained in:
Jonah Williams
2019-12-02 17:04:37 -08:00
committed by GitHub
parent 0ce9206ef4
commit 8cf20f3be7
2 changed files with 34 additions and 2 deletions

View File

@@ -224,8 +224,12 @@ class VsCode {
return null;
}
final String jsonString = fs.file(packageJsonPath).readAsStringSync();
final Map<String, dynamic> jsonObject = castStringKeyedMap(json.decode(jsonString));
return jsonObject['version'] as String;
try {
final Map<String, dynamic> jsonObject = castStringKeyedMap(json.decode(jsonString));
return jsonObject['version'] as String;
} on FormatException {
return null;
}
}
}