(issue)
| 910 | * @since 4.0.0 |
| 911 | */ |
| 912 | export const defaultLeafHook: LeafHook = (issue): string => { |
| 913 | const message = findMessage(issue) |
| 914 | if (message !== undefined) return message |
| 915 | switch (issue._tag) { |
| 916 | case "InvalidType": |
| 917 | return getExpectedMessage(InternalAnnotations.getExpected(issue.ast), issue) |
| 918 | case "InvalidValue": { |
| 919 | const expected = findExpected(issue) |
| 920 | if (expected !== undefined) return getExpectedMessage(expected, issue) |
| 921 | const input = formatInput(issue) |
| 922 | return input === undefined ? "Expected a valid value" : `Invalid data ${input}` |
| 923 | } |
| 924 | case "MissingKey": |
| 925 | return "Missing key" |
| 926 | case "UnexpectedKey": { |
| 927 | const input = formatInput(issue) |
| 928 | return input === undefined ? "Expected no excess property" : `Unexpected key with value ${input}` |
| 929 | } |
| 930 | case "Forbidden": |
| 931 | return "Forbidden operation" |
| 932 | case "OneOf": { |
| 933 | const input = formatInput(issue) |
| 934 | return input === undefined |
| 935 | ? "Expected exactly one member to match" |
| 936 | : `Expected exactly one member to match the input ${input}` |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | /** |
| 942 | * Callback type used to format {@link Filter} issues into strings. |
no test coverage detected