Skip to content

Commit c30f998

Browse files
authored
[flutter_tools] Fix missing stack trace from daemon (flutter#144113)
When the daemon throws an exception, the receiving client is unable to surface stack traces from the daemon. This is because it is sent with the `trace` key here: https://github.com/flutter/flutter/blob/1e8dd1e4d6d70c5e06525bea3fb164a03d7a6c1d/packages/flutter_tools/lib/src/daemon.dart#L308 But the client tries to read it with the `stackTrace` key here: https://github.com/flutter/flutter/blob/1e8dd1e4d6d70c5e06525bea3fb164a03d7a6c1d/packages/flutter_tools/lib/src/daemon.dart#L343 Thanks to @mraleph for spotting this! *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* b/326825892
1 parent 331769f commit c30f998

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/flutter_tools/lib/src/daemon.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class DaemonConnection {
340340
// This is an error response.
341341
_logger.printTrace('<- Error response received from daemon, id = $id');
342342
final Object error = data['error']!;
343-
final String stackTrace = data['stackTrace'] as String? ?? '';
343+
final String stackTrace = data['trace'] as String? ?? '';
344344
_outgoingRequestCompleters.remove(id)?.completeError(error, StackTrace.fromString(stackTrace));
345345
} else {
346346
_logger.printTrace('<- Response received from daemon, id = $id');

packages/flutter_tools/test/general.shard/daemon_test.dart

+12-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,18 @@ void main() {
173173

174174
final String id = message.data['id']! as String;
175175
daemonStreams.inputs.add(DaemonMessage(<String, dynamic>{'id': id, 'error': 'some_error', 'trace': 'stack trace'}));
176-
expect(requestFuture, throwsA('some_error'));
176+
177+
Object? gotError;
178+
StackTrace? gotStackTrace;
179+
try {
180+
await requestFuture;
181+
} on Object catch (error, stackTrace) {
182+
gotError = error;
183+
gotStackTrace = stackTrace;
184+
}
185+
186+
expect(gotError, 'some_error');
187+
expect(gotStackTrace.toString(), 'stack trace');
177188
});
178189
});
179190

0 commit comments

Comments
 (0)