-
Notifications
You must be signed in to change notification settings - Fork 394
[Property Editor] Better error handling #9101
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,11 @@ import 'package:devtools_app_shared/utils.dart'; | |
| import 'package:dtd/dtd.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:json_rpc_2/json_rpc_2.dart'; | ||
| import 'package:logging/logging.dart'; | ||
|
|
||
| import '../analytics/constants.dart'; | ||
| import '../framework/app_error_handling.dart'; | ||
| import 'api_classes.dart'; | ||
|
|
||
| final _log = Logger('editor_client'); | ||
|
|
||
| /// A client wrapper that connects to an editor over DTD. | ||
| /// | ||
| /// Changes made to the editor services/events should be considered carefully to | ||
|
|
@@ -262,18 +260,40 @@ class EditorClient extends DisposableController | |
| }) async { | ||
| final method = editableArgumentsMethodName.value; | ||
| if (method == null) return null; | ||
| final response = await _callLspApi( | ||
| method, | ||
| params: { | ||
| 'type': 'Object', // This is required by DTD. | ||
| 'textDocument': textDocument.toJson(), | ||
| 'position': position.toJson(), | ||
| }, | ||
| ); | ||
| final result = response.result[Field.result]; | ||
| return result != null | ||
| ? EditableArgumentsResult.fromJson(result as Map<String, Object?>) | ||
| : null; | ||
| try { | ||
| final response = await _callLspApi( | ||
| method, | ||
| params: { | ||
| 'type': 'Object', // This is required by DTD. | ||
| 'textDocument': textDocument.toJson(), | ||
| 'position': position.toJson(), | ||
| }, | ||
| ); | ||
| final result = response.result[Field.result]; | ||
| return result != null | ||
| ? EditableArgumentsResult.fromJson(result as Map<String, Object?>) | ||
| : null; | ||
| } on RpcException catch (e, st) { | ||
| // We expect content modified errors if a user edits their code before the | ||
| // request completes. Therefore it is safe to ignore. | ||
| if (e.code != AnalysisServerError.contentModifiedError.code) { | ||
| final errorMessage = e.message; | ||
| reportError( | ||
| errorMessage, | ||
| errorType: PropertyEditorSidebar.getEditableArgumentsIdentifier, | ||
| stack: st, | ||
| ); | ||
| } | ||
| return null; | ||
| } catch (e, st) { | ||
| final errorMessage = 'Unknown error: $e'; | ||
| reportError( | ||
| errorMessage, | ||
| errorType: PropertyEditorSidebar.getEditableArgumentsIdentifier, | ||
| stack: st, | ||
| ); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /// Requests that the Analysis Server makes a code edit for an argument. | ||
|
|
@@ -301,17 +321,25 @@ class EditorClient extends DisposableController | |
| }, | ||
| ); | ||
| return EditArgumentResponse(success: true); | ||
| } on RpcException catch (e) { | ||
| } on RpcException catch (e, st) { | ||
| final errorMessage = e.message; | ||
| _log.severe(errorMessage); | ||
| reportError( | ||
| errorMessage, | ||
| errorType: PropertyEditorSidebar.editArgumentIdentifier, | ||
| stack: st, | ||
| ); | ||
| return EditArgumentResponse( | ||
| success: false, | ||
| errorCode: e.code, | ||
| errorMessage: errorMessage, | ||
| ); | ||
| } catch (e) { | ||
| } catch (e, st) { | ||
| final errorMessage = 'Unknown error: $e'; | ||
| _log.severe(errorMessage); | ||
| reportError( | ||
| errorMessage, | ||
| errorType: PropertyEditorSidebar.editArgumentIdentifier, | ||
| stack: st, | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| return EditArgumentResponse( | ||
| success: false, | ||
| errorMessage: 'Unknown error: $e', | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we could reduce duplication by putting this in a
finallyclause. If we had a variableString? errorMessagedefined before the try, theon RpcExceptionandcatchblocks could just set theerrorMessagevariable that is used in thefinallyblock that callsreportErrorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!