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

Function writeAtPaths

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

Source from the content-addressed store, hash-verified

1219
1220// each error's text, any path in it written whole
1221const writeAtPaths = (
1222 error: ArkError,
1223 config: ResolvedConfig,
1224 locale: Locale.Resolved
1225): void => {
1226 if (locale !== config.locale) writtenLocales.set(error, locale)
1227 error.propString ??= stringifyPath(error.path)
1228 const bases = basesByUnion.get(error)
1229 if (bases && error.expected === undefined) {
1230 const expected: string[] = []
1231 for (const e of bases) {
1232 writeError(e, config, locale)
1233 if (!expected.includes(e.expected)) expected.push(e.expected)
1234 }
1235 // as the locale lists alternatives, which for en is as describeBranches
1236 // does and a standalone validator writes
1237 error.expected = locale.list(expected, "or")
1238 }
1239 if (error.code === "union") {
1240 for (const e of error.errors) {
1241 // usually at its own path, whose string is then written once
1242 if (pathEquals(e.path, error.path)) e.propString ??= error.propString
1243 writeAtPaths(e, config, locale)
1244 }
1245 // a message configured for each of its errors is its own
1246 const shared =
1247 error.message === undefined &&
1248 unconfigured(error, config) &&
1249 sharedMessageOf(error.errors, locale)
1250 if (shared) {
1251 error.message = shared
1252 sharing.add(error)
1253 }
1254 // a message configured for one below the root is written once, at its
1255 // whole path, from what it expects of the value there
1256 if (
1257 error.path.length !== 0 &&
1258 error.expected === undefined &&
1259 error.message === undefined &&
1260 !unconfigured(error, config)
1261 )
1262 error.expected = relativeTo(error, config, locale, "").expected
1263 }
1264 if (renderer && locale !== renderer.en) renderer.write(error, config, locale)
1265 else writeText(error, config, locale)
1266}
1267
1268const unconfigured = (error: ArkError, config: ResolvedConfig): boolean => {
1269 const message = configuredMessageOf(error)

Callers 2

writeErrorFunction · 0.85
relativeToFunction · 0.85

Calls 12

stringifyPathFunction · 0.90
writeErrorFunction · 0.85
pathEqualsFunction · 0.85
unconfiguredFunction · 0.85
sharedMessageOfFunction · 0.70
relativeToFunction · 0.70
writeTextFunction · 0.70
getMethod · 0.65
setMethod · 0.45
pushMethod · 0.45
addMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected