-
Notifications
You must be signed in to change notification settings - Fork 58
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
Attempt to recover from invalid YAML #107
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0f246f8
Attempt to recover from invalid YAML
DanTup e0d32ae
Add an "ErrorListener" to collect errors during parsing
DanTup 585bfe9
Use YamlExceptions directly + tidy up error reporting
DanTup 53d358e
Add missing copyright
DanTup 338b102
Disallow errorListener when not recovering, and don't call error list…
DanTup 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 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'yaml_exception.dart'; | ||
|
||
/// A listener that is notified of [YamlError]s during scanning/parsing. | ||
abstract class ErrorListener { | ||
/// This method is invoked when an [error] has been found in the YAML. | ||
void onError(YamlException error); | ||
} | ||
|
||
/// An [ErrorListener] that collects all errors into [errors]. | ||
class ErrorCollector extends ErrorListener { | ||
final List<YamlException> errors = []; | ||
|
||
@override | ||
void onError(YamlException error) => errors.add(error); | ||
} |
This file contains 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 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 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 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 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 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
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.
I don't currently see any value in passing in an
errorListener
ifrecovery
isfalse
, nor any value in settingrecovery
totrue
if there's noerrorListener
. We might consider having the value ofrecovery
be implied byerrorListener != null
(that is, make the error listener the only parameter, withnull
implying no recovery).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.
In the server where I'm testing this, we care about recovery but not errors (diagnostics aren't produced here, it's in response to a completion request):
https://github.com/dart-lang/sdk/blob/d55dc9c42a4362307e4deb5c97eea2db43d951e4/pkg/analysis_server/lib/src/services/completion/yaml/yaml_completion_generator.dart#L87-L95
I could create a
NullErrorListener
and we could pass that, although it may seem a bit strange to pass aNullErrorListener
in order to trigger recovery. What do you think?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.
Yeah, that would be a bit odd. We might still want to add an assert that the error listener is always
null
whenrecovery
itfalse
, because that combination doesn't really make sense. Ifrecovery
isfalse
(and there's an error in the YAML) then the single exception will always be thrown and there's no value to having a listener.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.
Done!