Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromVar should return an Either String a #30

Open
dmjio opened this issue Oct 18, 2019 · 3 comments · May be fixed by #35
Open

fromVar should return an Either String a #30

dmjio opened this issue Oct 18, 2019 · 3 comments · May be fixed by #35

Comments

@dmjio
Copy link
Owner

dmjio commented Oct 18, 2019

For more parse failure information, we should use the latest and greatest readEither function from Text.Read.readEither.

@dmjio
Copy link
Owner Author

dmjio commented Oct 18, 2019

Also note for decoding basic type the failure information returned isn't that useful, so this change might not be worth it.

>>> readEither "hello" :: Either String Int
Left "Prelude.read: no parse"

igrep added a commit to igrep/envy that referenced this issue Jan 24, 2020
Problem
====

- Handling `Maybe` values in the `Parser` monad is troublesome.
- Even `envMaybe` mixes up variable-not-found-error with others,
  which makes it obscure to use both `Nothing` and `Left String`
  as its error.

Solution
====

Change the error type of `Parser a` from just a `String` into
a dedicated error ADT `ParseError`.

NOTE
====

- Fix dmjio#30 as a bonus!
igrep added a commit to igrep/envy that referenced this issue Jan 24, 2020
Problem
====

- Handling `Maybe` values in the `Parser` monad is troublesome.
- Even `envMaybe` mixes up variable-not-found-error with others,
  which makes it obscure to use both `Nothing` and `Left String`
  as its error.

Solution
====

Change the error type of `Parser a` from just a `String` into
a dedicated error ADT `ParseError`.

NOTE
====

- Fix dmjio#30 as a bonus!
igrep added a commit to igrep/envy that referenced this issue Jan 24, 2020
Problem
====

- Handling `Maybe` values in the `Parser` monad is troublesome.
- Even `envMaybe` mixes up variable-not-found-error with others,
  which makes the difference of `Nothing` and `Left String`
  obscure.

Solution
====

Change the error type of `Parser a` from just a `String` into
a dedicated error ADT `ParseError`.

NOTE
====

- Fix dmjio#30 as a bonus!
igrep added a commit to igrep/envy that referenced this issue Feb 4, 2020
Problem
====

- Handling `Maybe` values in the `Parser` monad is troublesome.
- Even `envMaybe` mixes up variable-not-found-error with others,
  which makes the difference of `Nothing` and `Left String`
  obscure.

Solution
====

Change the error type of `Parser a` from just a `String` into
a dedicated error ADT `ParseError`.

NOTE
====

- Fix dmjio#30 as a bonus!
@cideM
Copy link

cideM commented Nov 6, 2020

I'm trying to use URI from Text.URI together with Envy but I don't know how to line up the types and preserve error information. I started by wrapping URI in a newtype wrapper Url so that I don't get orphan instance warnings. GHC then tells me that

No instance for (Envy.Var Url)

which makes sense. So I implement Var but the fromVar method has the type fromVar :: String -> Maybe a so I'm immediately stuck because I need String -> Either Whatever Url or any type that let's me add a custom error message or error information.

Then I started wondering about the purpose of fromEnv :: Maybe a -> Parser a since Parser a clearly let's me return more error information. But that information is already lost when I'm trying to implement fromVar... 🤔

So long story short: the fact that fromVar already throws out all error information is to me a complete show stopper when it comes to Envy. Which is a shame because it seems that Haskell doesn't have many nice libraries in the env var parsing space 😞

@dmjio
Copy link
Owner Author

dmjio commented Nov 6, 2020

@cideM we can change fromVar to be fromVar :: String -> Either String a. I'd support that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants