MCPcopy Create free account
hub / github.com/arktypeio/arktype / writeRelative

Function writeRelative

ark/schema/shared/errors.ts:994–1021  ·  view source on GitHub ↗
(
	error: ArkError,
	config: ResolvedConfig,
	locale: Locale.Resolved
)

Source from the content-addressed store, hash-verified

992// form shows beside its path, so the paths of its errors are written from its
993// own; the line of one listing its errors, read first, keeps them whole
994const writeRelative = (
995 error: ArkError,
996 config: ResolvedConfig,
997 locale: Locale.Resolved
998): void => {
999 if (error.code !== "union") return
1000 for (const e of error.errors) writeRelative(e, config, locale)
1001 if (error.path.length === 0) return
1002 if (isCustom(error)) {
1003 // one configured for it was written at its own path from what it expects
1004 // there; one its errors share, or it was raised with, is kept as well
1005 if (unconfigured(error, config))
1006 error.expected = relativeTo(error, config, locale, error.message).expected
1007 return
1008 }
1009 // a union listing its errors names each one's path, so its line is as
1010 // written. Noted once: written again, as an error two unions list is, its
1011 // message is already the one written from its own path
1012 if (
1013 error.code === "union" &&
1014 listsErrors(error) &&
1015 (error as ArkIssue)._l === undefined
1016 )
1017 noteLine(error, error.message)
1018 const relative = relativeTo(error, config, locale)
1019 error.expected = relative.expected
1020 error.message = relative.message
1021}
1022
1023// a union or intersection written as if the data at its path were validated
1024// alone. A message is the error's own: a writer configured for it reads its

Callers 1

writeErrorFunction · 0.85

Calls 5

listsErrorsFunction · 0.90
unconfiguredFunction · 0.85
noteLineFunction · 0.85
isCustomFunction · 0.70
relativeToFunction · 0.70

Tested by

no test coverage detected