error-map.ts — astro Source File
Architecture documentation for error-map.ts, a typescript file in the astro codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR f426a7f0_b6be_5991_9420_b6012c0b085e["error-map.ts"] a2586aae_ce09_613d_4444_659268b61a89["core"] f426a7f0_b6be_5991_9420_b6012c0b085e --> a2586aae_ce09_613d_4444_659268b61a89 style f426a7f0_b6be_5991_9420_b6012c0b085e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { $ZodErrorMap } from 'zod/v4/core';
type TypeOrLiteralErrByPathEntry = {
code: 'invalid_type' | 'invalid_literal';
received: unknown;
expected: unknown[];
message: string | undefined;
};
export const errorMap: $ZodErrorMap = (issue) => {
const baseErrorPath = flattenErrorPath(issue.path ?? []);
if (issue.code === 'invalid_union') {
// Optimization: Combine type and literal errors for keys that are common across ALL union types
// Ex. a union between `{ key: z.literal('tutorial') }` and `{ key: z.literal('blog') }` will
// raise a single error when `key` does not match:
// > Did not match union.
// > key: Expected `'tutorial' | 'blog'`, received 'foo'
let typeOrLiteralErrByPath = new Map<string, TypeOrLiteralErrByPathEntry>();
for (const unionError of issue.errors.flat()) {
if (unionError.code === 'invalid_type') {
const flattenedErrorPath = flattenErrorPath(unionError.path);
if (typeOrLiteralErrByPath.has(flattenedErrorPath)) {
typeOrLiteralErrByPath.get(flattenedErrorPath)!.expected.push(unionError.expected);
} else {
typeOrLiteralErrByPath.set(flattenedErrorPath, {
code: unionError.code,
received: (unionError as any).received,
expected: [unionError.expected],
message: unionError.message,
});
}
}
}
const messages: string[] = [prefix(baseErrorPath, 'Did not match union.')];
const details: string[] = [...typeOrLiteralErrByPath.entries()]
// If type or literal error isn't common to ALL union types,
// filter it out. Can lead to confusing noise.
.filter(([, error]) => error.expected.length === issue.errors.flat().length)
.map(([key, error]) =>
key === baseErrorPath
? // Avoid printing the key again if it's a base error
`> ${getTypeOrLiteralMsg(error)}`
: `> ${prefix(key, getTypeOrLiteralMsg(error))}`,
);
if (details.length === 0) {
const expectedShapes: string[] = [];
for (const unionErrors of issue.errors) {
const expectedShape: string[] = [];
for (const _issue of unionErrors) {
// If the issue is a nested union error, show the associated error message instead of the
// base error message.
if (_issue.code === 'invalid_union') {
return errorMap(_issue as any);
}
const relativePath = flattenErrorPath(_issue.path)
.replace(baseErrorPath, '')
.replace(leadingPeriod, '');
if ('expected' in _issue && typeof _issue.expected === 'string') {
expectedShape.push(
// ... (73 more lines)
Domain
Subdomains
Dependencies
- core
Source
Frequently Asked Questions
What does error-map.ts do?
error-map.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in error-map.ts?
error-map.ts defines 6 function(s): errorMap, flattenErrorPath, getTypeOrLiteralMsg, prefix, stringify, unionExpectedVals.
What does error-map.ts depend on?
error-map.ts imports 1 module(s): core.
Where is error-map.ts in the architecture?
error-map.ts is located at packages/db/src/core/integration/error-map.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/db/src/core/integration).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free