parseIpsCrash function

NativeCrash? parseIpsCrash(
  1. String ips, {
  2. required String bundleId,
  3. String? path,
})

The crash in one .ips report when it belongs to bundleId, else null.

Implementation

NativeCrash? parseIpsCrash(String ips, {required String bundleId, String? path}) {
  final nl = ips.indexOf('\n');
  if (nl < 0) return null;
  try {
    final head = jsonDecode(ips.substring(0, nl)) as Map<String, Object?>;
    if (head['bundleID'] != bundleId) return null;
    final body = jsonDecode(ips.substring(nl + 1)) as Map<String, Object?>;
    final exception = (body['exception'] as Map?)?.cast<String, Object?>() ?? const {};
    final termination = (body['termination'] as Map?)?.cast<String, Object?>() ?? const {};
    final type = exception['type'] as String?;
    final signal = exception['signal'] as String?;
    final reasons = (termination['reasons'] as List?)?.cast<Object?>().join('; ');
    final reason = [
      if (type != null) signal == null ? type : '$type ($signal)',
      if (reasons != null && reasons.isNotEmpty)
        reasons
      else if (termination['indicator'] != null)
        '${termination['indicator']}',
    ].join(': ');
    final images = (body['usedImages'] as List?) ?? const [];
    final threads = (body['threads'] as List?)?.cast<Map>() ?? const [];
    final crashed = threads.where((t) => t['triggered'] == true).firstOrNull;
    final frames = <String>[
      for (final f in ((crashed?['frames'] as List?) ?? const []).cast<Map>().take(6))
        '${f['symbol'] ?? '?'} (${_imageName(images, f['imageIndex'])})',
    ];
    return NativeCrash(
      time: _ipsTime(head['timestamp'] as String?) ?? DateTime.now(),
      reason: reason.isEmpty ? 'the app crashed' : reason,
      frames: frames,
      source: path,
    );
  } on Object {
    return null;
  }
}