Skip to content

fix(docs): reject YAML errors in multi-document migration - #1139

Open
Creatixpy wants to merge 1 commit into
e18e:mainfrom
Creatixpy:fix/yaml-multi-document-errors
Open

Creatixpy wants to merge 1 commit into
e18e:mainfrom
Creatixpy:fix/yaml-multi-document-errors

Conversation

@Creatixpy

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Related to #840. This corrects the multi-document migration example; the broader performance and compliance comparison remains open.

📚 Description

Implementation assisted by AI tools.

The multi-document example converts documents even when yaml reports parsing errors. For example, ---\na: 1\na: 2\n makes js-yaml.loadAll throw, but the documented replacement silently returns {a: 2}.

Check errors on an empty stream and on each document before calling toJSON(), so the example throws the first reported parsing error. This also handles malformed directives that produce no documents.

Validation

  • Local pnpm build, pnpm lint, changed-file Prettier, and git diff --check passed with Node 20.20.2 and pnpm 10.33.3. The corrected snippet also passed a strict standalone TypeScript check.
  • Executed the actual before/after snippets with yaml@2.9.1 against js-yaml@4.1.1 and js-yaml@5.4.2: 10 cases passed per version. The previous example silently accepted six malformed inputs; the corrected example rejects all six. Valid and empty inputs retain the replacement's previous results.
  • Pre-submission Build & Test passed on Node 20.x, 22.x, 24.x, and latest for 65ab92a against base f7f91a9. These results cover that tested revision; this PR's checks run separately.

Reviewed with the help of AI.

@maksimgm

Copy link
Copy Markdown
Contributor

tested this against yaml, throws on a bad doc and returns [] for empty input. lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants