MCPcopy Create free account
hub / github.com/Effect-TS/effect / defaultLeafHook

Function defaultLeafHook

packages/effect/src/SchemaIssue.ts:912–939  ·  view source on GitHub ↗
(issue)

Source from the content-addressed store, hash-verified

910 * @since 4.0.0
911 */
912export 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.

Callers 1

formatIssueFunction · 0.85

Calls 5

findMessageFunction · 0.85
getExpectedMessageFunction · 0.85
findExpectedFunction · 0.85
formatInputFunction · 0.85
getExpectedMethod · 0.45

Tested by

no test coverage detected