MCPcopy
hub / github.com/di-sukharev/opencommit / formatZodError

Function formatZodError

out/cli.cjs:34325–34375  ·  view source on GitHub ↗
(err, level = 0)

Source from the content-addressed store, hash-verified

34323 };
34324 exports2.SDKValidationError = SDKValidationError;
34325 function formatZodError(err, level = 0) {
34326 let pre = " ".repeat(level);
34327 pre = level > 0 ? `\u2502${pre}` : pre;
34328 pre += " ".repeat(level);
34329 let message = "";
34330 const append2 = (str2) => message += `
34331${pre}${str2}`;
34332 const len = err.issues.length;
34333 const headline = len === 1 ? `${len} issue found` : `${len} issues found`;
34334 if (len) {
34335 append2(`\u250C ${headline}:`);
34336 }
34337 for (const issue of err.issues) {
34338 let path5 = issue.path.join(".");
34339 path5 = path5 ? `<root>.${path5}` : "<root>";
34340 append2(`\u2502 \u2022 [${path5}]: ${issue.message} (${issue.code})`);
34341 switch (issue.code) {
34342 case "invalid_literal":
34343 case "invalid_type": {
34344 append2(`\u2502 Want: ${issue.expected}`);
34345 append2(`\u2502 Got: ${issue.received}`);
34346 break;
34347 }
34348 case "unrecognized_keys": {
34349 append2(`\u2502 Keys: ${issue.keys.join(", ")}`);
34350 break;
34351 }
34352 case "invalid_enum_value": {
34353 append2(`\u2502 Allowed: ${issue.options.join(", ")}`);
34354 append2(`\u2502 Got: ${issue.received}`);
34355 break;
34356 }
34357 case "invalid_union_discriminator": {
34358 append2(`\u2502 Allowed: ${issue.options.join(", ")}`);
34359 break;
34360 }
34361 case "invalid_union": {
34362 const len2 = issue.unionErrors.length;
34363 append2(`\u2502 \u2716\uFE0E Attemped to deserialize into one of ${len2} union members:`);
34364 issue.unionErrors.forEach((err2, i3) => {
34365 append2(`\u2502 \u2716\uFE0E Member ${i3 + 1} of ${len2}`);
34366 append2(`${formatZodError(err2, level + 1)}`);
34367 });
34368 }
34369 }
34370 }
34371 if (err.issues.length) {
34372 append2(`\u2514\u2500*`);
34373 }
34374 return message.slice(1);
34375 }
34376 }
34377});
34378

Callers 1

prettyMethod · 0.85

Calls 3

append2Function · 0.85
forEachMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…