Skip to content

Commit

Permalink
Fix throwing non-new Errors and literals
Browse files Browse the repository at this point in the history
  • Loading branch information
ddbeck committed Jul 9, 2024
1 parent 3a00c29 commit 3b34320
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/compute-baseline/src/browser-compat-data/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/compute-baseline/src/browser-compat-data/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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.`,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})`,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/compute-baseline/src/browser-compat-data/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]"}`,
);
}

0 comments on commit 3b34320

Please # to comment.