Skip to content

Commit b81f0da

Browse files
committed
validate: remove warning about throwing literal
Motivation: I'm working on the similar code in parser and don't want to replicate ESLint disable comment so figured out a proper way to solve it. Also throwing error with message will help with debuging if someone will have an issue with `validate` code.
1 parent 48003ed commit b81f0da

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/validation/validate.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,17 @@ export function validate(
4848
// If the schema used for validation is invalid, throw an error.
4949
assertValidSchema(schema);
5050

51-
const abortObj = Object.freeze({});
51+
const abortError = new GraphQLError(
52+
'Too many validation errors, error limit reached. Validation aborted.',
53+
);
5254
const errors: Array<GraphQLError> = [];
5355
const context = new ValidationContext(
5456
schema,
5557
documentAST,
5658
typeInfo,
5759
(error) => {
5860
if (errors.length >= maxErrors) {
59-
errors.push(
60-
new GraphQLError(
61-
'Too many validation errors, error limit reached. Validation aborted.',
62-
),
63-
);
64-
// eslint-disable-next-line @typescript-eslint/no-throw-literal
65-
throw abortObj;
61+
throw abortError;
6662
}
6763
errors.push(error);
6864
},
@@ -75,10 +71,11 @@ export function validate(
7571
// Visit the whole document with each instance of all provided rules.
7672
try {
7773
visit(documentAST, visitWithTypeInfo(typeInfo, visitor));
78-
} catch (e) {
79-
if (e !== abortObj) {
74+
} catch (e: unknown) {
75+
if (e === abortError) {
8076
throw e;
8177
}
78+
errors.push(e);
8279
}
8380
return errors;
8481
}

0 commit comments

Comments
 (0)