Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap VM service API methods in an error handler to convert any exceptions into type RPCError #2144

Merged
merged 11 commits into from Jun 16, 2023

Conversation

elliette
Copy link
Collaborator

@elliette elliette commented Jun 13, 2023

Fixes #2140, work towards flutter/flutter#126362

Future<T> Function() asyncCallback,
) {
try {
return asyncCallback();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it needs to be await asyncCallback() to catch exceptions inside the callback. Also, would be great to add a test to make sure the exceptions are caught.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified it to use asyncCallback().catchError(...) (adding an await would return result of type T not Future<T>.

Also pulled it into the shared utilities and added some tests.

Copy link
Contributor

@annagrin annagrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple of comments

) {
return asyncCallback().catchError((error) {
if (error is RPCError || error is SentinelException) {
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is possible to re-throw here? Otherwise we will lose the stack trace (it has been helpful in the past to see where the error happened)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't - but in reading the documentation I realized we can use test: to only catch exceptions that aren't RPCErrors or SentinelExceptions, so I've changed it to that.


try {
await wrapInErrorHandlerAsync('exceptionCallback', exceptionCallback);
fail("RPCError not thrown.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: use throwsA matcher

For example (from chrome proxy server tests):

await expectLater( service.removeBreakpoint(isolate.id!, ''), throwsRPCError, );

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm for some reason that pattern doesn't work on the last test case (it doesn't catch the exception). But I've updated the other test cases to that.

@auto-submit auto-submit bot merged commit 1551fe6 into dart-lang:master Jun 16, 2023
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DWDS error handling should align better with vm_service's error handling
2 participants