MCPcopy
hub / github.com/webpack/webpack / cleanError

Function cleanError

test/Errors.test.js:31–51  ·  test/Errors.test.js::cleanError

* @param {unknown} err an err * @returns {Record<string, EXPECTED_ANY>} a cleaned error

(err)

Source from the content-addressed store, hash-verified

29 * @returns {Record<string, EXPECTED_ANY>} a cleaned error
30 */
31function cleanError(err) {
32 /** @type {Record<string, EXPECTED_ANY>} */
33 const result = {};
34 const errObj = /** @type {Record<string, EXPECTED_ANY>} */ (err);
35 for (const key of Object.getOwnPropertyNames(errObj)) {
36 if (IGNORED_ERROR_KEYS.has(key)) continue;
37 result[key] = errObj[key];
38 }
39
40 if (result.message) {
41 result.message = errObj.message
42 .replace(ERROR_STACK_PATTERN, class="st">"")
43 class="cm">// `JSON.parse` SyntaxError wording differs across engines (V8 vs JSC).
44 .replace(
45 /SyntaxError: (?:Unexpected end of JSON input|JSON Parse error: Unexpected EOF)/,
46 class="st">"SyntaxError: <json parse error>"
47 );
48 }
49
50 return result;
51}
52
53/**
54 * @param {unknown} received received

Callers 1

printFunction · 0.85

Calls 2

hasMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected