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

Function errorLineOf

ark/schema/shared/errors.ts:1180–1197  ·  view source on GitHub ↗
(error: ArkError, locale: Locale.Resolved)

Source from the content-addressed store, hash-verified

1178// a written error's line of a summary: its message alone at the root or
1179// where it lists its errors, and after its path anywhere else
1180const errorLineOf = (error: ArkError, locale: Locale.Resolved): string => {
1181 if (error.path.length === 0) return error.message
1182 const listed = (error as ArkIssue)._l
1183 if (listed !== undefined) return listed
1184 // a labeled message names its value, so the key naming it is left out
1185 const label = (error as ArkIssue)._n
1186 if (label !== undefined) return labeledPathOf(error) + error.message
1187 // a sentence of its own unless it begins as the locale's own would, so
1188 // one configured as that text reads on from its path
1189 const custom = isCustom(error) && !beginsAsOwn(error, locale)
1190 const line = locale.line as LineWriter | undefined
1191 // en's, also where a locale passed as is lacks one, is written here
1192 if (line === undefined || line === writeLine)
1193 return `${error.propString}${custom ? ":" : ""} ${error.message}`
1194 // a writer's context is the error itself, copied only to say its message
1195 // is custom, since a copy costs more than the line it's read for
1196 return line((custom ? { ...error, custom } : error) as never, locale)
1197}
1198
1199/**
1200 * whether an error's message begins as the locale's own would from what it

Callers 2

summarizeFunction · 0.85
errors.tsFile · 0.85

Calls 4

labeledPathOfFunction · 0.90
beginsAsOwnFunction · 0.85
lineFunction · 0.85
isCustomFunction · 0.70

Tested by

no test coverage detected