Skip to content

Commit

Permalink
enable unicorn/throw-new-error rule (#2938)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Dec 8, 2022
1 parent 11e6ad1 commit 6a9d913
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 18 deletions.
9 changes: 9 additions & 0 deletions .changeset/sweet-olives-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'graphiql': patch
'@graphiql/toolkit': patch
'graphql-language-service': patch
'graphql-language-service-cli': patch
'monaco-graphql': patch
---

enable `unicorn/throw-new-error` rule
2 changes: 1 addition & 1 deletion examples/monaco-graphql-react-vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default function App() {
getSchema()
.then(data => {
if (!('data' in data)) {
throw Error(
throw new Error(
'this demo does not support subscriptions or http multipart yet',
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-toolkit/src/create-fetcher/createFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
httpFetch = options.fetch;
}
if (!httpFetch) {
throw Error('No valid fetcher implementation available');
throw new Error('No valid fetcher implementation available');
}
// simpler fetcher for schema requests
const simpleFetcher = createSimpleFetcher(options, httpFetch);
Expand All @@ -56,7 +56,7 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
const wsFetcher = getWsFetcher(options, fetcherOpts);

if (!wsFetcher) {
throw Error(
throw new Error(
`Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ${
options.subscriptionUrl
? `Provided URL ${options.subscriptionUrl} failed`
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-toolkit/src/create-fetcher/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const createWebsocketsFetcherFromUrl = (
} catch (err) {
if (errorHasCode(err)) {
if (err.code === 'MODULE_NOT_FOUND') {
throw Error(
throw new Error(
"You need to install the 'graphql-ws' package to use websockets when passing a 'subscriptionUrl'",
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/src/components/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
const majorVersion = parseInt(React.version.slice(0, 2), 10);

if (majorVersion < 16) {
throw Error(
throw new Error(
[
'GraphiQL 0.18.0 and after is not compatible with React 15 or below.',
'If you are using a CDN source (jsdelivr, unpkg, etc), follow this example:',
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-language-service-cli/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function _getOutline(queryText: string): EXIT_CODE {
if (outline) {
process.stdout.write(JSON.stringify(outline, null, 2));
} else {
throw Error('Error parsing or no outline tree found');
throw new Error('Error parsing or no outline tree found');
}
} catch (error) {
process.stderr.write(formatUnknownError(error) + '\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function getDefinitionQueryResultForNamedType(
);

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

if (defNodes.length === 0) {
throw Error(`Definition not found for GraphQL type ${typeName}`);
throw new Error(`Definition not found for GraphQL type ${typeName}`);
}

const definitions: Array<Definition> = [];
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function getDefinitionQueryResultForFragmentSpread(
);

if (defNodes.length === 0) {
throw Error(`Definition not found for GraphQL fragment ${name}`);
throw new Error(`Definition not found for GraphQL fragment ${name}`);
}
const definitions: Array<Definition> = defNodes.map(
({ filePath, content, definition }) =>
Expand Down Expand Up @@ -150,7 +150,7 @@ function getDefinitionForFragmentDefinition(
): Definition {
const name = definition.name;
if (!name) {
throw Error('Expected ASTNode to have a Name.');
throw new Error('Expected ASTNode to have a Name.');
}

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/LanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class LanguageService {
},
});
} catch (err) {
throw Error(
throw new Error(
`Failed parsing externalFragmentDefinitions string:\n${this._externalFragmentDefinitionsString}`,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/graphqlMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function setupMode(defaults: MonacoGraphQLAPI): IDisposable {
try {
return client!.getLanguageServiceWorker(...uris);
} catch (err) {
throw Error('Error fetching graphql language service worker');
throw new Error('Error fetching graphql language service worker');
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/languageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class DiagnosticsAdapter {

if (variablesUris) {
if (variablesUris.length < 1) {
throw Error('no variables URI strings provided to validate');
throw new Error('no variables URI strings provided to validate');
}
const jsonSchema = await worker.doGetVariablesJSONSchema(
resource.toString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/schemaLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export const defaultSchemaLoader: SchemaLoader = (schemaConfig, parser) => {
if (documentAST) {
return buildASTSchema(documentAST, buildSchemaOptions);
}
throw Error('no schema supplied');
throw new Error('no schema supplied');
};
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ export const getStringSchema = (schemaConfig: SchemaConfig) => {
documentString: printSchema(schema),
};
}
throw Error('no schema supplied');
throw new Error('no schema supplied');
};
2 changes: 1 addition & 1 deletion scripts/renameFileExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ if (tempPath) {
rimraf.sync(tempRenamePath);
});
} else {
throw Error(`Could not generate temporary path\n${tempRenamePath}`);
throw new Error(`Could not generate temporary path\n${tempRenamePath}`);
}
4 changes: 2 additions & 2 deletions scripts/set-resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const path = require('path');
async function setResolution() {
const [, , tag] = process.argv;
if (!tag) {
throw Error('no tag provided');
throw new Error('no tag provided');
}

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

0 comments on commit 6a9d913

Please sign in to comment.