decode method

  1. @override
Future<String?> decode(
  1. String stack, {
  2. required List<List<int>> symbolFiles,
})

The decoded stack for stack, exactly as the VM printed it, using symbolFiles (the bytes of the matching .symbols files). Null when the stack cannot be decoded with them.

Implementation

@override
Future<String?> decode(
  String stack, {
  required List<List<int>> symbolFiles,
}) async {
  for (final List<int> file in symbolFiles) {
    final Dwarf? dwarf;
    try {
      dwarf = Dwarf.fromBytes(Uint8List.fromList(file));
    } on Object {
      continue;
    }
    if (dwarf == null) continue;
    try {
      final List<String> lines = await Stream<String>.fromIterable(
        stack.split('\n'),
      ).transform(DwarfStackTraceDecoder(dwarf)).toList();
      final String decoded = lines.join('\n');
      // A decoder given the wrong file passes every frame through
      // unchanged; that is not a decoding.
      if (decoded.split('\n').any((String line) =>
          line.trimLeft().startsWith('#') && !line.contains(' abs '))) {
        return decoded;
      }
    } on Object {
      continue;
    }
  }
  return null;
}