Skip to content
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

BREAKING(csv): remove ParseError #5405

Merged
merged 6 commits into from
Jul 16, 2024

Conversation

timreichen
Copy link
Contributor

@timreichen timreichen commented Jul 10, 2024

What's changed

ParseError, which is thrown in parse(), has been removed and replaced in favor of SyntaxError. The startLine, line and column properties have been removed also. Error messages have remained unchanged.

Motivation

This change was made to align parse() with other parse() functions in the Standard Library, and JSON.parse(), which throw SyntaxError, and without any special properties. This all helps with providing consistent behavior across the Standard Library.

Migration guide

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

- import { parse, ParseError } from "@std/csv/parse";
+ import { parse } from "@std/csv/parse";

try {
  parse(`a,b,🐱"`);
} catch (error) {
- if (error instanceof ParseError) {
+ if (error instanceof SyntaxError) {
    // ...
  }
}

@github-actions github-actions bot added the csv label Jul 10, 2024
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.34%. Comparing base (ef28e13) to head (c713119).

Files Patch % Lines
csv/_io.ts 89.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5405      +/-   ##
==========================================
- Coverage   96.35%   96.34%   -0.01%     
==========================================
  Files         458      458              
  Lines       37751    37729      -22     
  Branches     5576     5573       -3     
==========================================
- Hits        36374    36351      -23     
- Misses       1335     1336       +1     
  Partials       42       42              

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

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

Just found a nit. Otherwise, LGTM! Thanks for this. @kt3k, PTAL.

csv/parse_stream_test.ts Outdated Show resolved Hide resolved
@iuioiua
Copy link
Collaborator

iuioiua commented Jul 10, 2024

Also, it does seem like some of these changes could've been done in a separate PR. Not a deal big enough to change now or block this PR, but more for future reference.

@iuioiua iuioiua marked this pull request as ready for review July 10, 2024 22:43
@iuioiua iuioiua requested a review from kt3k as a code owner July 10, 2024 22:43
Comment on lines -53 to -55
assertEquals(error.startLine, 4);
assertEquals(error.line, 5);
assertEquals(error.column, 0);
Copy link
Member

Choose a reason for hiding this comment

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

These information will be unavailable. Is that fine?

WDYT? cc @iuioiua

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, true. We can store this data within Error.cause.

Copy link
Member

Choose a reason for hiding this comment

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

We can store this data within Error.cause.

Sounds a reasonable alternative to me. That use case is recommended in the 2nd example https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause#providing_structured_data_as_the_error_cause

But I'm a bit concerned about the unavailability of the type. err.cause seems always unknown type. The user need to check type and properties of cause before accessing it. On the other hand, if it's kept ParseError, these properties can be accessed after the user checked err instanceof ParseError, which feels a bit easier and clearer to me. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point. Actually, now, I'm wondering whether it's worth having those extra details at all. JSON.parse doesn't do this. E.g. JSON.parse("[1,2,3,") throws an error with .cause undefined. We might be fine without. I suggest removing these properties. If it's a sufficiently significant issue in the future, we can revisit. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. Let's try this and see the community reactions.

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

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

LGTM once the PR description is complete with what's changed, motivations, and migration guide.

@iuioiua iuioiua merged commit edd21d5 into denoland:main Jul 16, 2024
16 checks passed
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.

None yet

3 participants