Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
add missing Forbidden handling (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Apr 11, 2023
1 parent 9d013b5 commit 3ab5df0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-mangos-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

add missing Forbidden handling
3 changes: 2 additions & 1 deletion src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ const go = untracedMethod(() =>
options
)
} else {
return (a, options) => PR.flatMap(ast.decode(a, options), (i2) => to(i2, options))
return (a, options) =>
handleForbidden(PR.flatMap(ast.decode(a, options), (i2) => to(i2, options)), options)
}
}
case "Declaration": {
Expand Down
41 changes: 18 additions & 23 deletions src/TreeFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ const getDescription = AST.getAnnotation<AST.DescriptionAnnotation>(
)

const getExpected = (ast: AST.AST): O.Option<string> =>
pipe(getIdentifier(ast), O.orElse(() => getTitle(ast)), O.orElse(() => getDescription(ast)))
pipe(
getIdentifier(ast),
O.orElse(() => getTitle(ast)),
O.orElse(() => getDescription(ast))
)

/** @internal */
export const formatExpected = (ast: AST.AST): string => {
Expand All @@ -110,43 +114,34 @@ export const formatExpected = (ast: AST.AST): string => {
case "UnknownKeyword":
case "VoidKeyword":
case "NeverKeyword":
return pipe(getExpected(ast), O.getOrElse(() => ast._tag))
return O.getOrElse(getExpected(ast), () => ast._tag)
case "Literal":
return pipe(getExpected(ast), O.getOrElse(() => formatActual(ast.literal)))
return O.getOrElse(getExpected(ast), () => formatActual(ast.literal))
case "UniqueSymbol":
return pipe(getExpected(ast), O.getOrElse(() => formatActual(ast.symbol)))
return O.getOrElse(getExpected(ast), () => formatActual(ast.symbol))
case "Union":
return ast.types.map(formatExpected).join(" or ")
case "TemplateLiteral":
return pipe(getExpected(ast), O.getOrElse(() => formatTemplateLiteral(ast)))
return O.getOrElse(getExpected(ast), () => formatTemplateLiteral(ast))
case "Tuple":
return pipe(getExpected(ast), O.getOrElse(() => "<anonymous tuple or array schema>"))
return O.getOrElse(getExpected(ast), () => "<anonymous tuple or array schema>")
case "TypeLiteral":
return pipe(getExpected(ast), O.getOrElse(() => "<anonymous type literal schema>"))
return O.getOrElse(getExpected(ast), () => "<anonymous type literal schema>")
case "Enums":
return pipe(
return O.getOrElse(
getExpected(ast),
O.getOrElse(() => ast.enums.map((_, value) => JSON.stringify(value)).join(" | "))
() => ast.enums.map((_, value) => JSON.stringify(value)).join(" | ")
)
case "Lazy":
return pipe(
getExpected(ast),
O.getOrElse(() => "<anonymous lazy schema>")
)
return O.getOrElse(getExpected(ast), () => "<anonymous lazy schema>")
case "Declaration":
return pipe(
getExpected(ast),
O.getOrElse(() => "<anonymous declaration schema>")
)
return O.getOrElse(getExpected(ast), () => "<anonymous declaration schema>")
case "Refinement":
return pipe(
getExpected(ast),
O.getOrElse(() => "<anonymous refinement schema>")
)
return O.getOrElse(getExpected(ast), () => "<anonymous refinement schema>")
case "Transform":
return pipe(
return O.getOrElse(
getExpected(ast),
O.getOrElse(() => `${formatExpected(ast.from)} -> ${formatExpected(ast.to)}`)
() => `${formatExpected(ast.from)} -> ${formatExpected(ast.to)}`
)
}
}
Expand Down

0 comments on commit 3ab5df0

Please sign in to comment.