Skip to content

Commit 63dc8f2

Browse files
refactor: remove DetailledError, not supported by Listr renderer (#8525)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent d821961 commit 63dc8f2

File tree

17 files changed

+74
-105
lines changed

17 files changed

+74
-105
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-codegen/flutter-freezed": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@graphql-codegen/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-codegen/visitor-plugin-common/v/2.13.0) (from `2.12.0`, in `dependencies`)

.changeset/great-mails-yawn.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@graphql-codegen/cli': patch
3+
'@graphql-codegen/core': patch
4+
'@graphql-codegen/visitor-plugin-common': patch
5+
'@graphql-codegen/near-operation-file-preset': patch
6+
'@graphql-codegen/plugin-helpers': patch
7+
---
8+
9+
remove `DetailledError`, not supported by Listr renderer

packages/graphql-codegen-cli/src/cli.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { generate } from './generate-and-save.js';
22
import { init } from './init/index.js';
33
import { createContext } from './config.js';
44
import { lifecycleHooks } from './hooks.js';
5-
import { DetailedError } from '@graphql-codegen/plugin-helpers';
65

76
export async function runCli(cmd: string): Promise<number> {
87
await ensureGraphQlPackage();
@@ -33,14 +32,12 @@ export async function ensureGraphQlPackage() {
3332
try {
3433
await import('graphql');
3534
} catch (e) {
36-
throw new DetailedError(
37-
`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency!`,
38-
`
39-
To install "graphql", run:
40-
yarn add graphql
41-
Or, with NPM:
42-
npm install --save graphql
43-
`
35+
throw new Error(
36+
`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency! \n
37+
To install "graphql", run:
38+
yarn add graphql
39+
Or, with NPM:
40+
npm install --save graphql`
4441
);
4542
}
4643
}

packages/graphql-codegen-cli/src/codegen.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import {
2-
DetailedError,
32
Types,
43
CodegenPlugin,
54
normalizeOutputParam,
65
normalizeInstanceOrArray,
76
normalizeConfig,
87
getCachedDocumentNodeFromSchema,
9-
isDetailedError,
108
} from '@graphql-codegen/plugin-helpers';
119
import { codegen } from '@graphql-codegen/core';
1210

@@ -51,7 +49,7 @@ const makeDefaultLoader = (from: string) => {
5149
};
5250
};
5351

54-
type Ctx = { errors: DetailedError[] | Error[] };
52+
type Ctx = { errors: Error[] };
5553

5654
function createCache(): <T>(namespace: string, key: string, factory: () => Promise<T>) => Promise<T> {
5755
const cache = new Map<string, Promise<unknown>>();
@@ -123,9 +121,8 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
123121
const generateKeys = Object.keys(config.generates || {});
124122

125123
if (generateKeys.length === 0) {
126-
throw new DetailedError(
127-
'Invalid Codegen Configuration!',
128-
`
124+
throw new Error(
125+
`Invalid Codegen Configuration! \n
129126
Please make sure that your codegen config file contains the "generates" field, with a specification for the plugins you need.
130127
131128
It should looks like that:
@@ -136,18 +133,16 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
136133
my-file.ts:
137134
- plugin1
138135
- plugin2
139-
- plugin3
140-
`
136+
- plugin3`
141137
);
142138
}
143139

144140
for (const filename of generateKeys) {
145141
const output = (generates[filename] = normalizeOutputParam(config.generates[filename]));
146142

147143
if (!output.preset && (!output.plugins || output.plugins.length === 0)) {
148-
throw new DetailedError(
149-
'Invalid Codegen Configuration!',
150-
`
144+
throw new Error(
145+
`Invalid Codegen Configuration! \n
151146
Please make sure that your codegen config file has defined plugins list for output "${filename}".
152147
153148
It should looks like that:
@@ -173,9 +168,8 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
173168
(generates[filename].schema as unknown as any[]).length === 0)
174169
)
175170
) {
176-
throw new DetailedError(
177-
'Invalid Codegen Configuration!',
178-
`
171+
throw new Error(
172+
`Invalid Codegen Configuration! \n
179173
Please make sure that your codegen config file contains either the "schema" field
180174
or every generated file has its own "schema" field.
181175
@@ -419,11 +413,7 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
419413
}
420414

421415
if (executedContext.errors.length > 0) {
422-
const errors = executedContext.errors.map(subErr =>
423-
isDetailedError(subErr)
424-
? `${subErr.message} for "${subErr.source}"${subErr.details}`
425-
: subErr.message || subErr.toString()
426-
);
416+
const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
427417
const newErr = new AggregateError(executedContext.errors, `${errors.join('\n\n')}`);
428418
// Best-effort to all stack traces for debugging
429419
newErr.stack = `${newErr.stack}\n\n${executedContext.errors.map(subErr => subErr.stack).join('\n\n')}`;

packages/graphql-codegen-cli/src/config.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
22
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
33
import { resolve } from 'path';
44
import {
5-
DetailedError,
65
Types,
76
Profiler,
87
createProfiler,
@@ -156,8 +155,7 @@ export async function loadContext(configFilePath?: string): Promise<CodegenConte
156155

157156
if (!result) {
158157
if (configFilePath) {
159-
throw new DetailedError(
160-
`Config ${configFilePath} does not exist`,
158+
throw new Error(
161159
`
162160
Config ${configFilePath} does not exist.
163161
@@ -168,18 +166,16 @@ export async function loadContext(configFilePath?: string): Promise<CodegenConte
168166
);
169167
}
170168

171-
throw new DetailedError(
172-
`Unable to find Codegen config file!`,
173-
`
169+
throw new Error(
170+
`Unable to find Codegen config file! \n
174171
Please make sure that you have a configuration file under the current directory!
175172
`
176173
);
177174
}
178175

179176
if (result.isEmpty) {
180-
throw new DetailedError(
181-
`Found Codegen config file but it was empty!`,
182-
`
177+
throw new Error(
178+
`Found Codegen config file but it was empty! \n
183179
Please make sure that you have a valid configuration file under the current directory!
184180
`
185181
);

packages/graphql-codegen-cli/src/plugins.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DetailedError, Types, CodegenPlugin } from '@graphql-codegen/plugin-helpers';
1+
import { Types, CodegenPlugin } from '@graphql-codegen/plugin-helpers';
22
import { resolve } from 'path';
33

44
export async function getPluginByName(
@@ -23,8 +23,7 @@ export async function getPluginByName(
2323
return await pluginLoader(moduleName);
2424
} catch (err) {
2525
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
26-
throw new DetailedError(
27-
`Unable to load template plugin matching ${name}`,
26+
throw new Error(
2827
`
2928
Unable to load template plugin matching '${name}'.
3029
Reason:
@@ -43,8 +42,7 @@ export async function getPluginByName(
4342
)
4443
.join('');
4544

46-
throw new DetailedError(
47-
`Unable to find template plugin matching ${name}`,
45+
throw new Error(
4846
`
4947
Unable to find template plugin matching '${name}'
5048
Install one of the following packages:

packages/graphql-codegen-cli/src/utils/cli-error.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { DetailedError } from '@graphql-codegen/plugin-helpers';
2-
3-
type CompositeError = Error | DetailedError;
1+
type CompositeError = Error;
42
type ListrError = Error & { errors: CompositeError[] };
53
export function isListrError(err: Error & { name?: unknown; errors?: unknown }): err is ListrError {
64
return err.name === 'ListrError' && Array.isArray(err.errors) && err.errors.length > 0;

packages/graphql-codegen-cli/tests/codegen.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('Codegen Executor', () => {
112112
throw new Error(SHOULD_NOT_THROW_STRING);
113113
} catch (e) {
114114
expect(e.message).not.toBe(SHOULD_NOT_THROW_STRING);
115-
expect(e.message).toBe('Invalid Codegen Configuration!');
115+
expect(e.message).toMatch('Invalid Codegen Configuration!');
116116
}
117117
});
118118

@@ -143,7 +143,7 @@ describe('Codegen Executor', () => {
143143
expect(output.length).toBe(1);
144144
} catch (e) {
145145
expect(e.message).not.toBe(SHOULD_NOT_THROW_STRING);
146-
expect(e.message).not.toBe('Invalid Codegen Configuration!');
146+
expect(e.message).not.toMatch('Invalid Codegen Configuration!');
147147
}
148148
});
149149

@@ -159,7 +159,7 @@ describe('Codegen Executor', () => {
159159

160160
throw new Error(SHOULD_NOT_THROW_STRING);
161161
} catch (e) {
162-
expect(e.message).toBe('Invalid Codegen Configuration!');
162+
expect(e.message).toMatch('Invalid Codegen Configuration!');
163163
expect(e.message).not.toBe(SHOULD_NOT_THROW_STRING);
164164
}
165165
});
@@ -177,7 +177,7 @@ describe('Codegen Executor', () => {
177177
throw new Error(SHOULD_NOT_THROW_STRING);
178178
} catch (e) {
179179
expect(e.message).not.toBe(SHOULD_NOT_THROW_STRING);
180-
expect(e.message).toBe('Invalid Codegen Configuration!');
180+
expect(e.message).toMatch('Invalid Codegen Configuration!');
181181
}
182182
});
183183

packages/graphql-codegen-core/src/codegen.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
DetailedError,
32
Types,
43
isComplexPluginOutput,
54
federationSpec,
@@ -283,10 +282,8 @@ function validateDuplicateDocuments(files: Types.DocumentFile[]) {
283282
.join('');
284283

285284
const definitionKindName = kind.replace('Definition', '').toLowerCase();
286-
throw new DetailedError(
287-
`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}`,
288-
`
289-
Not all ${definitionKindName}s have an unique name
285+
throw new Error(
286+
`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}: \n
290287
${list}
291288
`
292289
);

packages/graphql-codegen-core/src/execute-plugin.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DetailedError, Types, CodegenPlugin, Profiler, createNoopProfiler } from '@graphql-codegen/plugin-helpers';
1+
import { Types, CodegenPlugin, Profiler, createNoopProfiler } from '@graphql-codegen/plugin-helpers';
22
import { DocumentNode, GraphQLSchema, buildASTSchema } from 'graphql';
33

44
export interface ExecutePluginOptions {
@@ -17,9 +17,8 @@ export interface ExecutePluginOptions {
1717

1818
export async function executePlugin(options: ExecutePluginOptions, plugin: CodegenPlugin): Promise<Types.PluginOutput> {
1919
if (!plugin || !plugin.plugin || typeof plugin.plugin !== 'function') {
20-
throw new DetailedError(
21-
`Invalid Custom Plugin "${options.name}"`,
22-
`
20+
throw new Error(
21+
`Invalid Custom Plugin "${options.name}" \n
2322
Plugin ${options.name} does not export a valid JS object with "plugin" function.
2423
2524
Make sure your custom plugin is written in the following form:
@@ -54,9 +53,8 @@ export async function executePlugin(options: ExecutePluginOptions, plugin: Codeg
5453
`Plugin ${options.name} validate`
5554
);
5655
} catch (e) {
57-
throw new DetailedError(
58-
`Plugin "${options.name}" validation failed:`,
59-
`
56+
throw new Error(
57+
`Plugin "${options.name}" validation failed: \n
6058
${e.message}
6159
`
6260
);

packages/plugins/dart/flutter-freezed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"dependencies": {
1616
"@graphql-codegen/plugin-helpers": "^2.6.0",
1717
"@graphql-codegen/schema-ast": "^2.5.0",
18-
"@graphql-codegen/visitor-plugin-common": "2.12.0",
18+
"@graphql-codegen/visitor-plugin-common": "2.13.0",
1919
"auto-bind": "~4.0.0",
2020
"tslib": "~2.4.0",
2121
"change-case-all": "1.0.14"

packages/plugins/other/visitor-plugin-common/src/enum-values.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { EnumValuesMap, ParsedEnumValuesMap } from './types.js';
22
import { GraphQLSchema, isEnumType, GraphQLEnumType } from 'graphql';
3-
import { DetailedError } from '@graphql-codegen/plugin-helpers';
43
import { parseMapper } from './mappers.js';
54

65
function escapeString(str: string) {
@@ -37,9 +36,9 @@ export function parseEnumValues({
3736
const invalidMappings = Object.keys(mapOrStr).filter(gqlName => !allEnums.includes(gqlName));
3837

3938
if (invalidMappings.length > 0) {
40-
throw new DetailedError(
41-
`Invalid 'enumValues' mapping!`,
42-
`The following types does not exist in your GraphQL schema: ${invalidMappings.join(', ')}`
39+
throw new Error(
40+
`Invalid 'enumValues' mapping! \n
41+
The following types does not exist in your GraphQL schema: ${invalidMappings.join(', ')}`
4342
);
4443
}
4544

@@ -74,9 +73,9 @@ export function parseEnumValues({
7473
},
7574
};
7675
}
77-
throw new DetailedError(
78-
`Invalid "enumValues" configuration`,
79-
`Enum "${gqlIdentifier}": expected string or object (with enum values mapping)`
76+
throw new Error(
77+
`Invalid "enumValues" configuration \n
78+
Enum "${gqlIdentifier}": expected string or object (with enum values mapping)`
8079
);
8180
}, {} as ParsedEnumValuesMap);
8281
}

packages/presets/near-operation-file/src/resolve-document-imports.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isUsingTypes, Types, DetailedError } from '@graphql-codegen/plugin-helpers';
1+
import { isUsingTypes, Types } from '@graphql-codegen/plugin-helpers';
22
import {
33
generateImportStatement,
44
ImportSource,
@@ -88,13 +88,10 @@ export function resolveDocumentImports<T>(
8888
externalFragments,
8989
};
9090
} catch (e) {
91-
throw new DetailedError(
92-
`Unable to validate GraphQL document!`,
93-
`
94-
File ${documentFile.location} caused error:
95-
${e.message || e.toString()}
96-
`,
97-
documentFile.location
91+
throw new Error(
92+
`Unable to validate GraphQL document! \n
93+
File ${documentFile.location} caused error:
94+
${e.message || e.toString()}`
9895
);
9996
}
10097
});

packages/utils/plugins-helpers/src/errors.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/utils/plugins-helpers/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from './types.js';
33
export * from './utils.js';
44
export * from './helpers.js';
55
export * from './federation.js';
6-
export * from './errors.js';
76
export * from './getCachedDocumentNodeFromSchema.js';
87
export * from './oldVisit.js';
98
export * from './profiler.js';

patches/listr2+4.0.5.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/node_modules/listr2/dist/index.cjs b/node_modules/listr2/dist/index.cjs
2+
index 97af302..8715bd9 100644
3+
--- a/node_modules/listr2/dist/index.cjs
4+
+++ b/node_modules/listr2/dist/index.cjs
5+
@@ -406,7 +406,7 @@ var _DefaultRenderer = class {
6+
}
7+
str = `${icon} ${str}`;
8+
let parsedStr;
9+
- let columns = process.stdout.columns ? process.stdout.columns : 80;
10+
+ let columns = process.stdout.columns ? process.stdout.columns : process.platform === 'win32' ? 1000 : 80;
11+
columns = columns - level * this.options.indentation - 2;
12+
switch (this.options.formatOutput) {
13+
case "truncate":

0 commit comments

Comments
 (0)