( input: ArkErrorContextInput, basePath: array<PropertyKey>, config: ResolvedConfig )
| 753 | } |
| 754 | |
| 755 | const 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 |
| 793 | const assignSymbols = (target: object, source: object) => { |
no test coverage detected