From 3b343202e0b8c0916e5f398d44f35b92c592f677 Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Tue, 9 Jul 2024 14:10:55 +0200 Subject: [PATCH] Fix throwing non-new Errors and literals --- .../compute-baseline/src/browser-compat-data/browser.ts | 4 ++-- .../compute-baseline/src/browser-compat-data/feature.ts | 8 ++++---- .../compute-baseline/src/browser-compat-data/release.ts | 2 +- .../src/browser-compat-data/supportStatements.ts | 2 +- packages/compute-baseline/src/browser-compat-data/walk.ts | 2 +- .../compute-baseline/src/browser-compat-data/walkUtils.ts | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/compute-baseline/src/browser-compat-data/browser.ts b/packages/compute-baseline/src/browser-compat-data/browser.ts index 4ce7d13b507..1d9a199f883 100644 --- a/packages/compute-baseline/src/browser-compat-data/browser.ts +++ b/packages/compute-baseline/src/browser-compat-data/browser.ts @@ -58,7 +58,7 @@ export class Browser { const curr = this.releases.find((r) => r.data.status === "current"); if (curr === undefined) { - throw Error(`${browser} does not have a "current" release`); + throw new Error(`${browser} does not have a "current" release`); } return curr; @@ -67,7 +67,7 @@ export class Browser { version(versionString: string): Release { const result = this.releases.find((r) => r.version === versionString); if (result === undefined) { - throw Error(`${browser} does not have a '${versionString}' release.`); + throw new Error(`${browser} does not have a '${versionString}' release.`); } return result; } diff --git a/packages/compute-baseline/src/browser-compat-data/feature.ts b/packages/compute-baseline/src/browser-compat-data/feature.ts index ea469fe14ff..d7802dd00ad 100644 --- a/packages/compute-baseline/src/browser-compat-data/feature.ts +++ b/packages/compute-baseline/src/browser-compat-data/feature.ts @@ -27,7 +27,7 @@ export class Feature { constructor(id: string, featureData: unknown) { if (!isFeatureData(featureData)) { - throw `${id} is not valid feature`; + throw new Error(`${id} is not valid feature`); } this.id = id; @@ -77,13 +77,13 @@ export class Feature { ): { release: Release; qualifications?: Qualifications }[] { const support = this.data?.__compat?.support; if (support === undefined) { - throw Error("This feature contains no __compat object."); + throw new Error("This feature contains no __compat object."); } const statementOrStatements = support[browser.id]; if (statementOrStatements === undefined) { - throw Error(`${this} contains no support data for ${browser.name}`); + throw new Error(`${this} contains no support data for ${browser.name}`); } const rawStatements = Array.isArray(statementOrStatements) @@ -95,7 +95,7 @@ export class Feature { const s = statement(raw, browser, this); if (!(s instanceof RealSupportStatement)) { - throw Error( + throw new Error( `${this.id} contains non-real values for ${browser.name}. Cannot expand support.`, ); } diff --git a/packages/compute-baseline/src/browser-compat-data/release.ts b/packages/compute-baseline/src/browser-compat-data/release.ts index 3db2140e008..004b9432ff5 100644 --- a/packages/compute-baseline/src/browser-compat-data/release.ts +++ b/packages/compute-baseline/src/browser-compat-data/release.ts @@ -36,7 +36,7 @@ export class Release { compare(otherRelease: Release) { if (otherRelease.browser !== this.browser) { - throw Error( + throw new Error( `Cannot compare releases of differing browsers (${this.browser} versus ${otherRelease.browser})`, ); } diff --git a/packages/compute-baseline/src/browser-compat-data/supportStatements.ts b/packages/compute-baseline/src/browser-compat-data/supportStatements.ts index 4168096e868..8e4f926cb6b 100644 --- a/packages/compute-baseline/src/browser-compat-data/supportStatements.ts +++ b/packages/compute-baseline/src/browser-compat-data/supportStatements.ts @@ -153,7 +153,7 @@ export class RealSupportStatement extends SupportStatement { // returning `[this.browser.current()]` at least. supportedBy(): { release: Release; qualifications?: Qualifications }[] { if (this.browser === undefined) { - throw Error("This support statement's browser is unknown."); + throw new Error("This support statement's browser is unknown."); } if (this.version_added === false) { diff --git a/packages/compute-baseline/src/browser-compat-data/walk.ts b/packages/compute-baseline/src/browser-compat-data/walk.ts index 98d577bc0f5..d4c53ac240c 100644 --- a/packages/compute-baseline/src/browser-compat-data/walk.ts +++ b/packages/compute-baseline/src/browser-compat-data/walk.ts @@ -73,7 +73,7 @@ export function* walk(entryPoints: string | string[], data: BCD) { if (isFeatureData(queryResult)) { return lowLevelWalk(queryResult, entryPoint); } - throw Error("Unhandled traverse target"); + throw new Error("Unhandled traverse target"); }), ); } diff --git a/packages/compute-baseline/src/browser-compat-data/walkUtils.ts b/packages/compute-baseline/src/browser-compat-data/walkUtils.ts index 76c1077ffcd..1487485706b 100644 --- a/packages/compute-baseline/src/browser-compat-data/walkUtils.ts +++ b/packages/compute-baseline/src/browser-compat-data/walkUtils.ts @@ -38,7 +38,7 @@ export function descendantKeys(data: unknown, path?: string): string[] { return Object.keys(data).filter((key) => key !== "__compat"); } - throw Error( + throw new Error( `Unhandled traverse into descendants of object at ${path ?? "[root]"}`, ); }