[flutter_tools] fix type error in symbolize (#55212)

This commit is contained in:
Jonah Williams
2020-04-20 12:21:44 -07:00
committed by GitHub
parent 9e72bf565e
commit 6a390aa7dc
2 changed files with 60 additions and 7 deletions

View File

@@ -113,9 +113,46 @@ class SymbolizeCommand extends FlutterCommand {
}
}
typedef SymbolsTransformer = StreamTransformer<String, String> Function(Uint8List);
StreamTransformer<String, String> _defaultTransformer(Uint8List symbols) {
final Dwarf dwarf = Dwarf.fromBytes(symbols);
if (dwarf == null) {
throwToolExit('Failed to decode symbols file');
}
return DwarfStackTraceDecoder(dwarf, includeInternalFrames: true);
}
// A no-op transformer for `DwarfSymbolizationService.test`
StreamTransformer<String, String> _testTransformer(Uint8List buffer) {
return StreamTransformer<String, String>.fromHandlers(
handleData: (String data, EventSink<String> sink) {
sink.add(data);
},
handleDone: (EventSink<String> sink) {
sink.close();
},
handleError: (dynamic error, StackTrace stackTrace, EventSink<String> sink) {
sink.addError(error, stackTrace);
}
);
}
/// A service which decodes stack traces from Dart applications.
class DwarfSymbolizationService {
const DwarfSymbolizationService();
const DwarfSymbolizationService({
SymbolsTransformer symbolsTransformer = _defaultTransformer,
}) : _transformer = symbolsTransformer;
/// Create a DwarfSymbolizationService with a no-op transformer for testing.
@visibleForTesting
factory DwarfSymbolizationService.test() {
return const DwarfSymbolizationService(
symbolsTransformer: _testTransformer
);
}
final SymbolsTransformer _transformer;
/// Decode a stack trace from [input] and place the results in [output].
///
@@ -129,17 +166,13 @@ class DwarfSymbolizationService {
@required IOSink output,
@required Uint8List symbols,
}) async {
final Dwarf dwarf = Dwarf.fromBytes(symbols);
if (dwarf == null) {
throwToolExit('Failed to decode symbols file');
}
final Completer<void> onDone = Completer<void>();
StreamSubscription<void> subscription;
subscription = input
.cast<List<int>>()
.transform(const Utf8Decoder())
.transform(const LineSplitter())
.transform(DwarfStackTraceDecoder(dwarf, includeInternalFrames: true))
.transform(_transformer(symbols))
.listen((String line) {
try {
output.writeln(line);