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

Function errorOfContext

ark/schema/shared/errors.ts:755–790  ·  view source on GitHub ↗
(
	input: ArkErrorContextInput,
	basePath: array<PropertyKey>,
	config: ResolvedConfig
)

Source from the content-addressed store, hash-verified

753}
754
755const errorOfContext = (
756 input: ArkErrorContextInput,
757 basePath: array<PropertyKey>,
758 config: ResolvedConfig
759): ArkError => {
760 const { relativePath, prefixPath } = input
761 let error: Record<string, unknown>
762 // an input without path keys, e.g. a union's, is copied whole
763 if (
764 !("path" in input) &&
765 !("relativePath" in input) &&
766 !("prefixPath" in input) &&
767 !("propString" in input)
768 )
769 error = { data: input.data, path: [...basePath], ...input }
770 else {
771 const path = [...(input.path ?? basePath)]
772 if (relativePath) path.push(...relativePath)
773 if (prefixPath) path.unshift(...prefixPath)
774 error = { data: input.data, path }
775 for (const k in input) if (!(k in pathKeys)) error[k] = input[k as never]
776 assignSymbols(error, input)
777 }
778 if (input.code === "union") {
779 const flat = flattenUnion(input.errors)
780 error.errors =
781 !prefixPath && !relativePath ?
782 flat
783 : flat.map(e => {
784 const copy = unwrittenError(e)
785 copy.path = conflatenateAll(prefixPath, e.path, relativePath) as never
786 return copy
787 })
788 }
789 return stampError(error as never, config, input)
790}
791
792// for...in skips the symbol keys a spread copies
793const assignSymbols = (target: object, source: object) => {

Callers 2

errorFromContextFunction · 0.85
invalidErrorFunction · 0.85

Calls 8

conflatenateAllFunction · 0.90
assignSymbolsFunction · 0.85
flattenUnionFunction · 0.85
unwrittenErrorFunction · 0.85
stampErrorFunction · 0.85
unshiftMethod · 0.80
mapMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected