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(testing): replace TimeError exception in favor of built-in error classes in some cases #5550

Merged
merged 11 commits into from
Jul 29, 2024

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Jul 26, 2024

What's changed

Previously, all exceptions within FakeTime threw TimeErrors. Now, some exceptions throw RangeErrors, and TypeErrors, depending on the nature of the error. @throws JSDoc tags have also been added to the documentation.

Motivation

This change was made for two main reasons:

  1. Reduce the number of imported symbols required to error-handle FakeTime.
  2. Provide more context behind the nature of the errors, via the error class names, and therefore allow errors to be more easily differentiated within FakeTime.

Migration guide

To migrate, when error-handling FakeTime, use the appropriate error class for the given error message (see table below for reference).

- import { FakeTime, TimeError } from "@std/testing/time";
+ import { FakeTime } from "@std/testing/time";

try {
  new FakeTime.restore(NaN);
} catch (error) {
- if (error instanceof TimeError && error.message === "Invalid start") {
+ if (error instanceof TypeError && error.message === "Invalid start time") {
    // ...
  }
}
Error message Corresponding error class
"Invalid start time" TypeError
"Time cannot go backwards" RangeError

Related

Towards #5476

Copy link

codecov bot commented Jul 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.48%. Comparing base (2b33b55) to head (d5c597b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5550   +/-   ##
=======================================
  Coverage   96.48%   96.48%           
=======================================
  Files         465      465           
  Lines       37772    37772           
  Branches     5580     5580           
=======================================
  Hits        36445    36445           
  Misses       1285     1285           
  Partials       42       42           

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

@iuioiua iuioiua marked this pull request as ready for review July 26, 2024 01:51
@iuioiua iuioiua requested a review from kt3k as a code owner July 26, 2024 01:51
@iuioiua
Copy link
Contributor Author

iuioiua commented Jul 26, 2024

@KyleJune, does this change seem reasonable to you?

testing/time.ts Outdated Show resolved Hide resolved
testing/time.ts Outdated Show resolved Hide resolved
testing/time.ts Outdated Show resolved Hide resolved
@KyleJune
Copy link
Contributor

@KyleJune, does this change seem reasonable to you?

Seems reasonable to me. I don't have any issues with this change.

@iuioiua iuioiua mentioned this pull request Jul 26, 2024
8 tasks
@iuioiua iuioiua changed the title BREAKING(testing): remove TimeError in favor of built-in error classes BREAKING(testing): replace TimeError exception in favor of built-in error classes in some cases Jul 29, 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 7eed8d0 into main Jul 29, 2024
14 checks passed
@iuioiua iuioiua deleted the testing-TimeError branch July 29, 2024 04:48
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.

3 participants