Skip to content

Commit

Permalink
[flutter_tools] Fix missing stack trace from daemon (#144113)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jiahaog authored Feb 27, 2024
1 parent 331769f commit c30f998
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class DaemonConnection {
// This is an error response.
_logger.printTrace('<- Error response received from daemon, id = $id');
final Object error = data['error']!;
final String stackTrace = data['stackTrace'] as String? ?? '';
final String stackTrace = data['trace'] as String? ?? '';
_outgoingRequestCompleters.remove(id)?.completeError(error, StackTrace.fromString(stackTrace));
} else {
_logger.printTrace('<- Response received from daemon, id = $id');
Expand Down
13 changes: 12 additions & 1 deletion packages/flutter_tools/test/general.shard/daemon_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,18 @@ void main() {

final String id = message.data['id']! as String;
daemonStreams.inputs.add(DaemonMessage(<String, dynamic>{'id': id, 'error': 'some_error', 'trace': 'stack trace'}));
expect(requestFuture, throwsA('some_error'));

Object? gotError;
StackTrace? gotStackTrace;
try {
await requestFuture;
} on Object catch (error, stackTrace) {
gotError = error;
gotStackTrace = stackTrace;
}

expect(gotError, 'some_error');
expect(gotStackTrace.toString(), 'stack trace');
});
});

Expand Down

0 comments on commit c30f998

Please sign in to comment.