MCPcopy
hub / github.com/prettier/prettier / getDocErrorMessage

Function getDocErrorMessage

src/document/utilities/invalid-doc-error.js:7–29  ·  view source on GitHub ↗
(doc)

Source from the content-addressed store, hash-verified

5 new Intl.ListFormat("en-US", { type: "disjunction" }).format(list);
6
7function getDocErrorMessage(doc) {
8 const type = doc === null ? "null" : typeof doc;
9 if (type !== "string" && type !== "object") {
10 return `Unexpected doc '${type}', \nExpected it to be 'string' or 'object'.`;
11 }
12
13 /* c8 ignore next 3 */
14 if (getDocType(doc)) {
15 throw new Error("doc is valid.");
16 }
17
18 // eslint-disable-next-line prettier-internal-rules/no-unnecessary-ast-path-call
19 const objectType = Object.prototype.toString.call(doc);
20 if (objectType !== "[object Object]") {
21 return `Unexpected doc '${objectType}'.`;
22 }
23
24 const EXPECTED_TYPE_VALUES = disjunctionListFormat(
25 [...VALID_OBJECT_DOC_TYPES].map((type) => `'${type}'`),
26 );
27
28 return `Unexpected doc.type '${doc.type}'.\nExpected it to be ${EXPECTED_TYPE_VALUES}.`;
29}
30
31class InvalidDocError extends Error {
32 name = "InvalidDocError";

Callers 1

constructorMethod · 0.85

Calls 4

getDocTypeFunction · 0.85
disjunctionListFormatFunction · 0.85
callMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…