natefaubion / purescript-routing-duplex

Unified parsing and printing for routes in PureScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Safe URI decoding/encoding

srghma opened this issue · comments

was implemented in #20 (comment)

does it make sense to introduce such change?

because right now it just unsafeThrowError

I don't really want to add partiality to a printer, especially since the failure mode is so obscure. I'm inclined to just filter out things that don't encode.

ok, this is possible

just want to confirm. You are for the 2d option:

  1. right now - fails silently with unsafeThrowError
  2. we can - fail silently by omitting the URIComponents that cannot be encoded / decoded
  3. we can - fail with an error

was

parse :: forall i o. RouteDuplex i o -> String -> Either Parser.RouteError o
parse (RouteDuplex _ dec) = Parser.run dec

-- | Renders a value of type `i` into a String representation of URI path,
-- | query and fragment (hash).
print :: forall i o. RouteDuplex i o -> i -> String
print (RouteDuplex enc _) = Printer.run <<< enc

now

data RouteParseError
  = RouteParseError RouteError
  | DecodeURIError String

parse :: forall i o. RouteDuplex i o -> String -> Either Parser.RouteParseError o
parse (RouteDuplex _ dec) = Parser.run dec

newtype PrintPathError = EncodeURIComponentError String

-- | Renders a value of type `i` into a String representation of URI path,
-- | query and fragment (hash).
print :: forall i o. RouteDuplex i o -> i -> Either PrintPathError String
print (RouteDuplex enc _) = Printer.run <<< enc