Skip to content

[yaml] Better recovering for list entry without - prefix - #2427

Open
FMorschel wants to merge 4 commits into
dart-lang:mainfrom
FMorschel:yaml-parsing
Open

[yaml] Better recovering for list entry without - prefix#2427
FMorschel wants to merge 4 commits into
dart-lang:mainfrom
FMorschel:yaml-parsing

Conversation

@FMorschel

Copy link
Copy Markdown

This is a suggestion to fix:

Where we recover from a list item without the - prefix and give it a more coherent error message.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.

@FMorschel
FMorschel requested a review from a team as a code owner June 11, 2026 16:45

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request improves error recovery and messaging when parsing YAML block sequences with list elements missing the '- ' prefix. It introduces tracking of token types at each indentation level in the scanner (_indentTypes) to detect if a missing colon error occurs within a block sequence, appending a helpful hint to the error message. The parser is also updated to handle the recovered key token as a sequence entry, and a test case has been added to verify this behavior. There are no review comments, so no further feedback is provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@FMorschel

Copy link
Copy Markdown
Author

Can you take a look or assign someone, please, @nex3? Thanks a lot!

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

Package publishing

Package Version Status Publish tag (post-merge)
package:api_summary 0.1.0-wip WIP (no publish necessary)
package:bazel_worker 1.1.5 already published at pub.dev
package:benchmark_harness 2.4.0 already published at pub.dev
package:boolean_selector 2.1.2 already published at pub.dev
package:browser_launcher 1.2.0-wip WIP (no publish necessary)
package:cli_config 0.2.1-wip WIP (no publish necessary)
package:cli_util 0.5.1 already published at pub.dev
package:clock 1.1.3-wip WIP (no publish necessary)
package:code_builder 4.12.0-wip WIP (no publish necessary)
package:coverage 1.15.1 already published at pub.dev
package:csslib 1.0.2 already published at pub.dev
package:extension_discovery 2.1.0 already published at pub.dev
package:file 7.0.2-wip WIP (no publish necessary)
package:file_testing 3.1.0-wip WIP (no publish necessary)
package:glob 2.1.3 already published at pub.dev
package:graphs 2.4.0-wip WIP (no publish necessary)
package:html 0.15.7-wip WIP (no publish necessary)
package:io 1.1.0-wip WIP (no publish necessary)
package:json_rpc_2 4.1.0 already published at pub.dev
package:markdown 7.4.0 ready to publish markdown-v7.4.0
package:mime 2.1.0-wip WIP (no publish necessary)
package:oauth2 2.0.5 already published at pub.dev
package:package_config 3.0.0 already published at pub.dev
package:pool 1.5.3-wip WIP (no publish necessary)
package:process 5.0.5 (error) pubspec version (5.0.5) and changelog (5.0.6-wip) don't agree
package:pub_semver 2.2.0 already published at pub.dev
package:pubspec_parse 1.6.0-wip WIP (no publish necessary)
package:source_map_stack_trace 2.1.3-wip WIP (no publish necessary)
package:source_maps 0.10.14-wip WIP (no publish necessary)
package:source_span 1.10.2 already published at pub.dev
package:sse 4.2.0 already published at pub.dev
package:stack_trace 1.12.2-wip (error) pubspec version (1.12.2-wip) and changelog (1.12.2-dev) don't agree
package:stream_channel 2.1.4 already published at pub.dev
package:stream_transform 2.1.2-wip WIP (no publish necessary)
package:string_scanner 1.4.2-wip WIP (no publish necessary)
package:term_glyph 1.2.3-wip WIP (no publish necessary)
package:test_reflective_loader 0.6.0 ready to publish test_reflective_loader-v0.6.0
package:timing 1.0.2 already published at pub.dev
package:unified_analytics 8.0.15 already published at pub.dev
package:watcher 1.2.2-wip WIP (no publish necessary)
package:yaml 3.1.4-wip WIP (no publish necessary)
package:yaml_edit 2.2.4 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

PR Health

Unused Dependencies ✔️
Package Status
yaml ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
yaml None 3.1.3 3.1.4-wip 3.1.4-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ⚠️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources
yaml ErrorListener yaml/yaml.dart::loadYaml::errorListener
yaml/yaml.dart::loadYamlNode::errorListener
yaml/yaml.dart::loadYamlDocument::errorListener
yaml ScalarEvent yaml_node.dart::YamlScalar::internal::scalar
yaml EventType event.dart::Event::type
event.dart::EventType::streamStart
event.dart::EventType::streamEnd
event.dart::EventType::documentStart
event.dart::EventType::documentEnd
event.dart::EventType::alias
event.dart::EventType::scalar
event.dart::EventType::sequenceStart
event.dart::EventType::sequenceEnd
event.dart::EventType::mappingStart
event.dart::EventType::mappingEnd
event.dart::EventType::values
event.dart::Event::new::type
event.dart::ScalarEvent::type

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Coverage ✔️
File Coverage
pkgs/yaml/lib/src/parser.dart 💚 94 % ⬆️ 0 %
pkgs/yaml/lib/src/scanner.dart 💚 95 % ⬆️ 0 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

License Headers ✔️
// Copyright (c) 2026, 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.

Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/bazel_worker/benchmark/benchmark.dart
pkgs/coverage/lib/src/coverage_options.dart
pkgs/html/example/main.dart
pkgs/pubspec_parse/test/git_uri_test.dart
pkgs/watcher/test/custom_watcher_factory_test.dart

This check can be disabled by tagging the PR with skip-license-check.

Comment thread pkgs/yaml/lib/src/scanner.dart Outdated

@sigurdm sigurdm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice - just a small suggestion.

@FMorschel

Copy link
Copy Markdown
Author

Thanks, @sigurdm! Done.

@FMorschel FMorschel changed the title [yaml] better recovering for list entry without - prefix [yaml] Better recovering for list entry without - prefix Jun 15, 2026
@FMorschel

Copy link
Copy Markdown
Author

I have a question.

How does the rolling of this package into the Dart SDK work?

Because I have a CL open (https://dart-review.googlesource.com/c/sdk/+/511260/1..2), which mentions the issue this fixes.

How does this get rolled into the SDK if that test will start to fail if we remove the annotation before this lands, and will fail if this lands with the annotation there?

@DanTup

DanTup commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

How does the rolling of this package into the Dart SDK work?

I don't know how up-to-date my knowledge is, but my understanding is:

Versions of external packages in the SDK are controlled by the DEPS file. For packages from this repo (tools), they are all controlled together by tools_rev which is currently 338a2c8:

https://github.com/dart-lang/sdk/blob/c9b0df8469a2cb58298dde065044df8eceaaae5f/DEPS#L152

There's a script in the SDK tools/rev_sdk_deps.dart that automates bumping those versions and producing a commit message that includes a summary of the changes it's bringing in, and here's an example commit:

dart-lang/sdk@fe2141a

So after this PR lands, that script could be used to produce a change, and the annotation removed in the same CL. When I've done this in the past, to avoid the CL being a noisy mix of dep revs and a functional change, I've selectively only included the one package update and made the commit message clear.

@sigurdm
sigurdm requested a review from jonasfj June 29, 2026 07:55
_scanner.scan();
_states.add(_State.BLOCK_SEQUENCE_ENTRY);
return _parseNode(block: true);
}

@jonasfj jonasfj Jun 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is entirely orthogonal to the changes in scanner.dart, except that now the scanner will most likely report the thing about how it expected a '-'.

And because if this, we are not okay using the token it insert to do some recovery? Instead of throwing YamlException?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We can't be sure that is what the user meant to do. I read the documentation for yaml just to work on this change, so I'm not an expert, but from what I could gather, the user could still be trying to write a key one indentation before the list but got the indentation wrong.

This part merely resolves this by considering it a list entry and stops us from throwing the YamlException below if we are recovering. If we are not recovering, the exception in scanner.dart will flow all the way up.

See:

https://github.com/dart-lang/tools/pull/2427/changes#diff-cfd2bd97aae0a6765f4aad97f742cce898d78c68e78956bff4ad6d4c7ab87fe2R151-R158

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@jonasfj, is the above explanation enough for you to merge this, or do you need anything else from me?

@jonasfj jonasfj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not 100% sure how all of this works 🙈

But at the top of my head, this looks reasonably safe, I won't block it.

@FMorschel

Copy link
Copy Markdown
Author

@jonasfj or @sigurdm, do you need anything else from me? Can we please land this? Thanks!

@jonasfj

jonasfj commented Jul 24, 2026

Copy link
Copy Markdown
Member

@sigurdm any reason we don't merge this when you're back?
(I think we're both currently out of office)

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.

4 participants