Skip to content

BREAKING(yaml): replace YamlError with SyntaxError in parse() #5446

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 1 commit into from
Jul 16, 2024

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Jul 15, 2024

What's changed

parse() now throws SyntaxError instead of YamlError. No changes in behavior have been made.

Motivation

This change was made to align @std/yaml with other parse() functions in the Standard Library, such as in @std/csv and @std/toml, and JSON.parse(), which all throw SyntaxError. This will also result in a slightly smaller API surface and allows the user to more easily differentiate between parse() and stringify() errors (stringify() will soon throw TypeError).

Migration guide

To migrate, compare against SyntaxError instead of YamlError when error-handling parse().

- import { parse, YamlError } from "@std/yaml/parse";
+ import { parse } from "@std/yaml/parse";

try {
  parse(`"`);
} catch (error) {
- if (error instanceof YamlError) {
+ if (error instanceof SyntaxError) {
    // ...
  }
}

Related

Towards #5340

@iuioiua iuioiua requested a review from kt3k as a code owner July 15, 2024 07:20
@github-actions github-actions bot added the yaml label Jul 15, 2024
Copy link

codecov bot commented Jul 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.35%. Comparing base (df388b1) to head (32c7472).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5446      +/-   ##
==========================================
- Coverage   96.35%   96.35%   -0.01%     
==========================================
  Files         461      461              
  Lines       37762    37761       -1     
  Branches     5576     5576              
==========================================
- Hits        36385    36383       -2     
- Misses       1335     1336       +1     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iuioiua iuioiua changed the title BREAKING(yaml): replace YamlError with SyntaxError in parse BREAKING(yaml): replace YamlError with SyntaxError in parse() Jul 15, 2024
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@iuioiua iuioiua merged commit 997139d into main Jul 16, 2024
19 checks passed
@iuioiua iuioiua deleted the yaml-SyntaxError branch July 16, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants