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

[Property Editor] Handle errors from the Analysis Server #8818

Merged
merged 7 commits into from
Jan 30, 2025

Conversation

elliette
Copy link
Member

Fixes #8817
Work towards #1948

Handles any errors from the Analysis Server in response to an editArgument request. These errors are unexpected states; we shouldn't be triggering them. Follow-up (#8774) to send these exceptions to analytics as well.

@elliette elliette requested a review from a team as a code owner January 29, 2025 00:14
@elliette elliette requested review from bkonyi and kenzieschmoll and removed request for a team and bkonyi January 29, 2025 00:14
Comment on lines 447 to 448
/// These should be kept in sync with those listed in:
/// pkg/analysis_server/lib/src/lsp/constants.dart
Copy link
Member

Choose a reason for hiding this comment

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

can we have a test that covers this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I was trying to think how we could test this. We can't pull in analysis_server as a dependency (otherwise I would just use the error definitions there instead) so I'm not sure how we could have a test to check they are in sync. Any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

can we load the raw content of this file from GitHub and parse it? A bit hacky but still could be worth it to have a way to catch changes

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed #8824 and added TODOs

final propertyName = property.name;
switch (errorType) {
case EditArgumentError.editArgumentInvalidParameter:
return 'Invalid parameter: $propertyName.';
Copy link
Member

Choose a reason for hiding this comment

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

what do you think about including the description in the EditArgumentError definitions so that the messages are defined where the enum values are? Something like:

enum EditArgumentError {
  editArgumentInvalidParameter(-32017, 'Invalid parameter')
  ...

  final String description;

General question. Seems like we use Argument in some places and Property in others. Should we pick a single term for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you think about including the description in the EditArgumentError definitions so that the messages are defined where the enum values are?

Yes, that's better! Made the change.

General question. Seems like we use Argument in some places and Property in others. Should we pick a single term for consistency?

I've been trying to use argument for the layer that calls the analysis server APIs (since the API methods are called editArgument and getEditableArguments) and property for the UI layer. The "conversion" from argument to property happens here:

...args
.map((arg) => argToProperty(arg))
.nonNulls
.map(
(property) => _EditablePropertyItem(
property: property,
controller: controller,
),
),

But I don't have a strong preference for renaming everywhere vs keeping as is!

@@ -37,6 +37,7 @@ dependencies:
http: ^1.1.0
image: ^4.1.3
intl: ^0.19.0
json_rpc_2: ^3.0.0
Copy link
Member

Choose a reason for hiding this comment

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

do we need to bring this dependency in? Is this for the RpcException type, and is this the type that DTD throws?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is for the RpcException type thrown by DTD. This used to be a dev dependency.

@@ -12,7 +12,7 @@ import 'package:test/test.dart';

// Benchmark size in kB.
const bundleSizeBenchmark = 5400;
const gzipBundleSizeBenchmark = 1550;
const gzipBundleSizeBenchmark = 1650;
Copy link
Member Author

Choose a reason for hiding this comment

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

Bundle size is now 1552kb, therefore bumping 1550 limit to 1650

if (errorResponse == null || errorResponse.success) return;
setState(() {
_serverError = _errorMessage(errorResponse.errorType, property: property);
_serverError =
errorResponse.errorType?.message ?? 'Encountered unknown error.';
Copy link
Member

Choose a reason for hiding this comment

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

do we still want to include the property in this error message? I think it would be helpful:
'${errorResponse.errorType?.message ?? 'Encountered unknown error.'} Property: $property.'

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

@kenzieschmoll kenzieschmoll left a comment

Choose a reason for hiding this comment

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

one more comment then lgtm

@elliette elliette merged commit 6b8b15e into flutter:master Jan 30, 2025
24 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.

[property editor] Handle error/success response from Analysis Server
2 participants