( ctx: InternalTraversal, errors: readonly ArkError[], meta: ArkEnv.meta, data: unknown )
| 676 | |
| 677 | /** adds a union's error from each branch's first */ |
| 678 | export const errorFromUnion = ( |
| 679 | ctx: InternalTraversal, |
| 680 | errors: readonly ArkError[], |
| 681 | meta: ArkEnv.meta, |
| 682 | data: unknown |
| 683 | ): ArkError => { |
| 684 | const path = pathAt(ctx.path) |
| 685 | const flat = flattenUnion(errors) |
| 686 | // a description written for it is its text, as it is a standalone build's |
| 687 | const isDescribed = |
| 688 | meta.description !== undefined && meta.keyword === undefined |
| 689 | const atBases = |
| 690 | !isDescribed && |
| 691 | meta.expected === undefined && |
| 692 | meta.message === undefined && |
| 693 | flat.length !== 0 && |
| 694 | flat.every(e => failsAtBasis(e, path)) |
| 695 | const error = stampError( |
| 696 | { |
| 697 | data, |
| 698 | path, |
| 699 | code: "union", |
| 700 | errors: atBases ? [] : flat, |
| 701 | // what it lists says what it expects, as a validator's, never its actual |
| 702 | meta: |
| 703 | atBases && meta.actual !== undefined ? { ...meta, actual: "" } : meta, |
| 704 | ...(isDescribed && { description: meta.description }) |
| 705 | } as never, |
| 706 | ctx.config |
| 707 | ) |
| 708 | if (atBases) basesByUnion.set(error, flat) |
| 709 | return ctx.addError(error) |
| 710 | } |
| 711 | |
| 712 | // a union whose every branch fails at its basis, at the union's own path, |
| 713 | // holds no errors and expects what the bases are, as a standalone validator's |
no test coverage detected