Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Apr 13, 2024
1 parent e5b2228 commit 697e9dc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
33 changes: 17 additions & 16 deletions deno/lib/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ export const makeIssue = (params: {
path: fullPath,
};

let errorMessage = issueData.message || "";
if (!errorMessage) {
const maps: ZodErrorMap[] = [];
for (let i = errorMaps.length - 1; i >= 0; i--) {
const map = errorMaps[i];
if (!map || maps.includes(map)) {
continue;
}
maps.push(map);
if (issueData.message) {
return {
...issueData,
path: fullPath,
message: issueData.message,
};
}

errorMessage = map(fullIssue, {
data,
defaultError: errorMessage,
}).message;
}
let errorMessage = "";
const maps = errorMaps
.filter((m) => !!m)
.slice()
.reverse() as ZodErrorMap[];
for (const map of maps) {
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
}

return {
Expand Down Expand Up @@ -73,15 +73,16 @@ export function addIssueToContext(
ctx: ParseContext,
issueData: IssueData
): void {
const overrideMap = getErrorMap();
const issue = makeIssue({
issueData: issueData,
data: ctx.data,
path: ctx.path,
errorMaps: [
ctx.common.contextualErrorMap, // contextual error map is first priority
ctx.schemaErrorMap, // then schema-bound map if available
getErrorMap(), // then global override map
defaultErrorMap, // then global default map
overrideMap, // then global override map
overrideMap === defaultErrorMap ? undefined : defaultErrorMap, // then global default map
].filter((x) => !!x) as ZodErrorMap[],
});
ctx.common.issues.push(issue);
Expand Down
33 changes: 17 additions & 16 deletions src/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ export const makeIssue = (params: {
path: fullPath,
};

let errorMessage = issueData.message || "";
if (!errorMessage) {
const maps: ZodErrorMap[] = [];
for (let i = errorMaps.length - 1; i >= 0; i--) {
const map = errorMaps[i];
if (!map || maps.includes(map)) {
continue;
}
maps.push(map);
if (issueData.message) {
return {
...issueData,
path: fullPath,
message: issueData.message,
};
}

errorMessage = map(fullIssue, {
data,
defaultError: errorMessage,
}).message;
}
let errorMessage = "";
const maps = errorMaps
.filter((m) => !!m)
.slice()
.reverse() as ZodErrorMap[];
for (const map of maps) {
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
}

return {
Expand Down Expand Up @@ -73,15 +73,16 @@ export function addIssueToContext(
ctx: ParseContext,
issueData: IssueData
): void {
const overrideMap = getErrorMap();
const issue = makeIssue({
issueData: issueData,
data: ctx.data,
path: ctx.path,
errorMaps: [
ctx.common.contextualErrorMap, // contextual error map is first priority
ctx.schemaErrorMap, // then schema-bound map if available
getErrorMap(), // then global override map
defaultErrorMap, // then global default map
overrideMap, // then global override map
overrideMap === defaultErrorMap ? undefined : defaultErrorMap, // then global default map
].filter((x) => !!x) as ZodErrorMap[],
});
ctx.common.issues.push(issue);
Expand Down

0 comments on commit 697e9dc

Please sign in to comment.