Skip to content

Commit 6a9d913

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

14 files changed

Lines changed: 27 additions & 18 deletions

File tree

.changeset/sweet-olives-flow.md

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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(),

0 commit comments

Comments
 (0)