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(fs): throw Deno.errors.NotSupported instead of SubdirectoryMoveError in move[Sync]() #5532

Merged
merged 3 commits into from
Jul 25, 2024

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Jul 24, 2024

What's changed

Previously, @std/fs/move threw SubdirectoryMoveError. Now, it throws Deno.errors.NotSupported.

Motivation

This change was made to reduce the API surface area by using an appropriate error class that's already built into the Deno runtime.

Migration guide

To migrate, compare against Deno.error.NotSupported instead of SubdirectoryMoveError when error-handling move() or moveSync().

- import { move, SubdirectoryMoveError } from "@std/fs/move";
+ import { move } from "@std/fs/move";

try {
  await move("./path/to/folder/subdir", "./path/to/folder");
} catch (error) {
- if (error instanceof SubdirectoryMoveError) {
+ if (error instanceof Deno.errors.NotSupported) {
    // ...
  }
}

Related

Towards #5476

@iuioiua iuioiua requested a review from kt3k as a code owner July 24, 2024 03:19
@iuioiua iuioiua enabled auto-merge (squash) July 24, 2024 03:19
@github-actions github-actions bot added the fs label Jul 24, 2024
Copy link

codecov bot commented Jul 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.51%. Comparing base (42693da) to head (61589a1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5532      +/-   ##
==========================================
- Coverage   96.51%   96.51%   -0.01%     
==========================================
  Files         465      465              
  Lines       37714    37705       -9     
  Branches     5576     5576              
==========================================
- Hits        36400    36391       -9     
  Misses       1272     1272              
  Partials       42       42              

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

@iuioiua iuioiua changed the title BREAKING(fs): replace SubdirectoryMoveError exception with Deno.errors.InvalidData BREAKING(fs): throw Deno.errors.InvalidData instead of SubdirectoryMoveError in move[Sync]() Jul 24, 2024
@iuioiua iuioiua mentioned this pull request Jul 24, 2024
8 tasks
@kt3k
Copy link
Member

kt3k commented Jul 24, 2024

InvalidData sounds a bit strange for describing this situation to me.

Is this worth the breaking change?

@iuioiua
Copy link
Contributor Author

iuioiua commented Jul 24, 2024

InvalidData sounds a bit strange for describing this situation to me.

How about Deno.errors.NotSupported if src is a sub-directory of dst and Deno.errors.AlreadyExists if src equals dst?

Is this worth the breaking change?

Yes. It's one less extraneous symbol that the user has to import.

@kt3k
Copy link
Member

kt3k commented Jul 25, 2024

It's one less extraneous symbol that the user has to import.

This doesn't sound a good reason for breaking change. There are many symbols we can remove if we optimize for fewer number of symbols.

@kt3k kt3k added the feedback welcome We want community's feedback on this issue or PR label Jul 25, 2024
@iuioiua
Copy link
Contributor Author

iuioiua commented Jul 25, 2024

Perhaps, we're asking the wrong question. I think the question we should be asking is: why should we have a custom SubdirectoryMoveError class if there already exists an extensive collection of built-in error classes that accomplish the same thing? This is the only custom error class in @std/fs. Why? Why not use what's in-built?

@kt3k
Copy link
Member

kt3k commented Jul 25, 2024

Ok. I changed my mind. Let's do this change, but let's use Deno.errors.NotSupported, which seems more reasonable to me.

@iuioiua iuioiua changed the title BREAKING(fs): throw Deno.errors.InvalidData instead of SubdirectoryMoveError in move[Sync]() BREAKING(fs): throw Deno.errors.NotSupported instead of SubdirectoryMoveError in move[Sync]() Jul 25, 2024
@iuioiua
Copy link
Contributor Author

iuioiua commented Jul 25, 2024

Great! Updated.

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 d6a6d8b into main Jul 25, 2024
16 checks passed
@iuioiua iuioiua deleted the fs-remove-SubdirectoryMoveError branch July 25, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback welcome We want community's feedback on this issue or PR fs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants