Skip to content

Commit 6a9d913

Browse files
authored
enable unicorn/throw-new-error rule (#2938)
1 parent 11e6ad1 commit 6a9d913

File tree

14 files changed

+27
-18
lines changed

14 files changed

+27
-18
lines changed

.changeset/sweet-olives-flow.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'graphiql': patch
3+
'@graphiql/toolkit': patch
4+
'graphql-language-service': patch
5+
'graphql-language-service-cli': patch
6+
'monaco-graphql': patch
7+
---
8+
9+
enable `unicorn/throw-new-error` rule

examples/monaco-graphql-react-vite/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default function App() {
160160
getSchema()
161161
.then(data => {
162162
if (!('data' in data)) {
163-
throw Error(
163+
throw new Error(
164164
'this demo does not support subscriptions or http multipart yet',
165165
);
166166
}

packages/graphiql-toolkit/src/create-fetcher/createFetcher.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
3030
httpFetch = options.fetch;
3131
}
3232
if (!httpFetch) {
33-
throw Error('No valid fetcher implementation available');
33+
throw new Error('No valid fetcher implementation available');
3434
}
3535
// simpler fetcher for schema requests
3636
const simpleFetcher = createSimpleFetcher(options, httpFetch);
@@ -56,7 +56,7 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
5656
const wsFetcher = getWsFetcher(options, fetcherOpts);
5757

5858
if (!wsFetcher) {
59-
throw Error(
59+
throw new Error(
6060
`Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ${
6161
options.subscriptionUrl
6262
? `Provided URL ${options.subscriptionUrl} failed`

packages/graphiql-toolkit/src/create-fetcher/lib.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const createWebsocketsFetcherFromUrl = (
8989
} catch (err) {
9090
if (errorHasCode(err)) {
9191
if (err.code === 'MODULE_NOT_FOUND') {
92-
throw Error(
92+
throw new Error(
9393
"You need to install the 'graphql-ws' package to use websockets when passing a 'subscriptionUrl'",
9494
);
9595
}

packages/graphiql/src/components/GraphiQL.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import {
5858
const majorVersion = parseInt(React.version.slice(0, 2), 10);
5959

6060
if (majorVersion < 16) {
61-
throw Error(
61+
throw new Error(
6262
[
6363
'GraphiQL 0.18.0 and after is not compatible with React 15 or below.',
6464
'If you are using a CDN source (jsdelivr, unpkg, etc), follow this example:',

packages/graphql-language-service-cli/src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function _getOutline(queryText: string): EXIT_CODE {
152152
if (outline) {
153153
process.stdout.write(JSON.stringify(outline, null, 2));
154154
} else {
155-
throw Error('Error parsing or no outline tree found');
155+
throw new Error('Error parsing or no outline tree found');
156156
}
157157
} catch (error) {
158158
process.stderr.write(formatUnknownError(error) + '\n');

packages/graphql-language-service/src/interface/getDefinition.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function getDefinitionQueryResultForNamedType(
5959
);
6060

6161
if (defNodes.length === 0) {
62-
throw Error(`Definition not found for GraphQL type ${name}`);
62+
throw new Error(`Definition not found for GraphQL type ${name}`);
6363
}
6464
const definitions: Array<Definition> = defNodes.map(
6565
({ filePath, content, definition }) =>
@@ -82,7 +82,7 @@ export async function getDefinitionQueryResultForField(
8282
);
8383

8484
if (defNodes.length === 0) {
85-
throw Error(`Definition not found for GraphQL type ${typeName}`);
85+
throw new Error(`Definition not found for GraphQL type ${typeName}`);
8686
}
8787

8888
const definitions: Array<Definition> = [];
@@ -119,7 +119,7 @@ export async function getDefinitionQueryResultForFragmentSpread(
119119
);
120120

121121
if (defNodes.length === 0) {
122-
throw Error(`Definition not found for GraphQL fragment ${name}`);
122+
throw new Error(`Definition not found for GraphQL fragment ${name}`);
123123
}
124124
const definitions: Array<Definition> = defNodes.map(
125125
({ filePath, content, definition }) =>
@@ -150,7 +150,7 @@ function getDefinitionForFragmentDefinition(
150150
): Definition {
151151
const name = definition.name;
152152
if (!name) {
153-
throw Error('Expected ASTNode to have a Name.');
153+
throw new Error('Expected ASTNode to have a Name.');
154154
}
155155

156156
return {

packages/monaco-graphql/src/LanguageService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class LanguageService {
140140
},
141141
});
142142
} catch (err) {
143-
throw Error(
143+
throw new Error(
144144
`Failed parsing externalFragmentDefinitions string:\n${this._externalFragmentDefinitionsString}`,
145145
);
146146
}

packages/monaco-graphql/src/graphqlMode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function setupMode(defaults: MonacoGraphQLAPI): IDisposable {
2626
try {
2727
return client!.getLanguageServiceWorker(...uris);
2828
} catch (err) {
29-
throw Error('Error fetching graphql language service worker');
29+
throw new Error('Error fetching graphql language service worker');
3030
}
3131
};
3232

packages/monaco-graphql/src/languageFeatures.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class DiagnosticsAdapter {
132132

133133
if (variablesUris) {
134134
if (variablesUris.length < 1) {
135-
throw Error('no variables URI strings provided to validate');
135+
throw new Error('no variables URI strings provided to validate');
136136
}
137137
const jsonSchema = await worker.doGetVariablesJSONSchema(
138138
resource.toString(),

packages/monaco-graphql/src/schemaLoader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export const defaultSchemaLoader: SchemaLoader = (schemaConfig, parser) => {
2828
if (documentAST) {
2929
return buildASTSchema(documentAST, buildSchemaOptions);
3030
}
31-
throw Error('no schema supplied');
31+
throw new Error('no schema supplied');
3232
};

packages/monaco-graphql/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ export const getStringSchema = (schemaConfig: SchemaConfig) => {
163163
documentString: printSchema(schema),
164164
};
165165
}
166-
throw Error('no schema supplied');
166+
throw new Error('no schema supplied');
167167
};

scripts/renameFileExtensions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ if (tempPath) {
5151
rimraf.sync(tempRenamePath);
5252
});
5353
} else {
54-
throw Error(`Could not generate temporary path\n${tempRenamePath}`);
54+
throw new Error(`Could not generate temporary path\n${tempRenamePath}`);
5555
}

scripts/set-resolution.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const path = require('path');
44
async function setResolution() {
55
const [, , tag] = process.argv;
66
if (!tag) {
7-
throw Error('no tag provided');
7+
throw new Error('no tag provided');
88
}
99

1010
const [package, version] = tag.split('@');
1111
if (!package || !version) {
12-
throw Error(`Invalid tag ${tag}`);
12+
throw new Error(`Invalid tag ${tag}`);
1313
}
1414
const pkgPath = path.resolve(path.join(process.cwd(), 'package.json'));
1515
const pkg = JSON.parse((await readFile(pkgPath, 'utf-8')).toString());

0 commit comments

Comments
 (0)