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

Catch FormatException from bad simulator log output (#90966)

parent 131b6b18
......@@ -858,9 +858,14 @@ class _IOSSimulatorLogReader extends DeviceLogReader {
// The log command predicate handles filtering, so every log eventMessage should be decoded and added.
final Match eventMessageMatch = _unifiedLoggingEventMessageRegex.firstMatch(line);
if (eventMessageMatch != null) {
final dynamic decodedJson = jsonDecode(eventMessageMatch.group(1));
if (decodedJson is String) {
_linesController.add(decodedJson);
final String message = eventMessageMatch.group(1);
try {
final dynamic decodedJson = jsonDecode(message);
if (decodedJson is String) {
_linesController.add(decodedJson);
}
} on FormatException {
globals.printError('Logger returned non-JSON response: $message');
}
}
}
......
......@@ -622,6 +622,12 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
});
group('unified logging', () {
BufferLogger logger;
setUp(() {
logger = BufferLogger.test();
});
testUsingContext('log reader handles escaped multiline messages', () async {
const String logPredicate = 'eventType = logEvent AND processImagePath ENDSWITH "My Super Awesome App" '
'AND (senderImagePath ENDSWITH "/Flutter" OR senderImagePath ENDSWITH "/libswiftCore.dylib" '
......@@ -676,6 +682,47 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
ProcessManager: () => fakeProcessManager,
FileSystem: () => fileSystem,
});
testUsingContext('log reader handles bad output', () async {
const String logPredicate = 'eventType = logEvent AND processImagePath ENDSWITH "My Super Awesome App" '
'AND (senderImagePath ENDSWITH "/Flutter" OR senderImagePath ENDSWITH "/libswiftCore.dylib" '
'OR processImageUUID == senderImageUUID) AND NOT(eventMessage CONTAINS ": could not find icon '
'for representation -> com.apple.") AND NOT(eventMessage BEGINSWITH "assertion failed: ") '
'AND NOT(eventMessage CONTAINS " libxpc.dylib ")';
fakeProcessManager.addCommand(const FakeCommand(
command: <String>[
'xcrun',
'simctl',
'spawn',
'123456',
'log',
'stream',
'--style',
'json',
'--predicate',
logPredicate,
],
stdout: '"eventMessage" : "message with incorrect escaping""',
));
final IOSSimulator device = IOSSimulator(
'123456',
simulatorCategory: 'iOS 11.0',
simControl: simControl,
);
final DeviceLogReader logReader = device.getLogReader(
app: await BuildableIOSApp.fromProject(mockIosProject, null),
);
final List<String> lines = await logReader.logLines.toList();
expect(lines, isEmpty);
expect(logger.errorText, contains('Logger returned non-JSON response'));
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
FileSystem: () => fileSystem,
Logger: () => logger,
});
});
});
......
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