Skip to content

Commit

Permalink
fix: type error (#73)
Browse files Browse the repository at this point in the history
This reverts a0f1abe. As it turns out ErrnoException was used on purpose, because that type includes the `code` property.

A comment was added in order to make this more clear.
  • Loading branch information
ComradeVanti authored Dec 20, 2023
1 parent eaf156e commit 7303ab6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/error-type-guards.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { HttpErrorBase } from "npm-registry-fetch";
import { AssertionError } from "assert";

/*
* Note: We are in a Node context, where Errors have the "code" property.
* We need to make sure we use Node's error type instead of the default one
* @see https://dev.to/jdbar/the-problem-with-handling-node-js-errors-in-typescript-and-the-workaround-m64
*/
import ErrnoException = NodeJS.ErrnoException;

/**
* @throws AssertionError The given parameter is not an error
*/
export function assertIsError(x: unknown): asserts x is Error {
export function assertIsError(x: unknown): asserts x is ErrnoException {
if (!(x instanceof Error))
throw new AssertionError({
message: "Argument was not an error!",
Expand Down

0 comments on commit 7303ab6

Please sign in to comment.