Skip to content

Commit 61d99e3

Browse files
nzakasmdjermanovic
andauthored
fix: Better error message for unserializable parser (#19384)
* fix: Better error message for unserializable parser fixes #19322 * Update messages/config-serialize-function.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update messages/config-serialize-function.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 758c66b commit 61d99e3

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/config/config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ function languageOptionsToJSON(languageOptions, objectKey = "languageOptions") {
110110
}
111111

112112
if (typeof value === "function") {
113-
throw new TypeError(`Cannot serialize key "${key}" in ${objectKey}: Function values are not supported.`);
113+
const error = new TypeError(`Cannot serialize key "${key}" in ${objectKey}: Function values are not supported.`);
114+
115+
error.messageTemplate = "config-serialize-function";
116+
error.messageData = { key, objectKey };
117+
118+
throw error;
114119
}
115120

116121
}

messages/config-serialize-function.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
module.exports = function({ key, objectKey }) {
4+
5+
// special case for parsers
6+
const isParser = objectKey === "parser" && (key === "parse" || key === "parseForESLint");
7+
const parserMessage = `
8+
This typically happens when you're using a custom parser that does not
9+
provide a "meta" property, which is how ESLint determines the serialized
10+
representation. Please open an issue with the maintainer of the custom parser
11+
and share this link:
12+
13+
https://eslint.org/docs/latest/extend/custom-parsers#meta-data-in-custom-parsers
14+
`.trim();
15+
16+
return `
17+
The requested operation requires ESLint to serialize configuration data,
18+
but the configuration key "${objectKey}.${key}" contains a function value,
19+
which cannot be serialized.
20+
21+
${
22+
isParser ? parserMessage : "Please double-check your configuration for errors."
23+
}
24+
25+
If you still have problems, please stop by https://eslint.org/chat/help to chat
26+
with the team.
27+
`.trimStart();
28+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy