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

Improve error messages from FromMultipart #36

Merged
merged 7 commits into from
Jun 5, 2020

Conversation

maksbotan
Copy link
Contributor

@maksbotan maksbotan commented May 29, 2020

Hi,

I've tried using servant-multipart and observed that error messages from parsing are not very informative. Therefore I decided to introduce Lenient mode, analogous to Capture.

@maksbotan
Copy link
Contributor Author

8.0 and 8.2 builds failed due to <> missing from Prelude (I've removed Data.Monoid import). How about we drop them and raise lower requirement on base to 4.8?

@fisx
Copy link
Member

fisx commented May 29, 2020

Thanks! Good error messages are useful. I will take a look at this soon.

8.0 and 8.2 builds failed due to <> missing from Prelude (I've removed Data.Monoid import). How about we drop them and raise lower requirement on base to 4.8?

I personally think supporting everything down to 8.0 is not too much to ask. As long as we don't have any evidence that nobody cares, I wouldn't touch it.

Anyway that would be a different PR, no?

@maksbotan
Copy link
Contributor Author

Okay, I've reverted that small change, now it should build on 8.0.

I have another thought: do we really need the "fromMultipart failed:" prefix in the error message? I suppose it should be OK to drop it and return the parser's message verbatim?

@fisx
Copy link
Member

fisx commented May 30, 2020

Okay, I've reverted that small change, now it should build on 8.0.

I have another thought: do we really need the "fromMultipart failed:" prefix in the error message? I suppose it should be OK to drop it and return the parser's message verbatim?

The extra prefix could be helpful, depending on how unhelpful the parser is, which depends on the user of the library, so I'm not sure we should depend on it.

Would "Could not decode multipart mime body: <parser error message>" be an improvement? I'd prefer something like this because it does not leak servant internals to the API.

Copy link
Member

@fisx fisx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice! Since it's a breaking change, I would like a second opinion, but I'd be happy to release this. Thanks @maksbotan!

src/Servant/Multipart.hs Outdated Show resolved Hide resolved
@@ -246,10 +258,10 @@ class FromMultipart tag a where
-- in a list of textual inputs and another list for
-- files, try to extract a value of type @a@. When
-- extraction fails, servant errors out with status code 400.
fromMultipart :: MultipartData tag -> Maybe a
fromMultipart :: MultipartData tag -> Either String a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are ways to make this change easier for the library users, but I'm not sure it should be. Perhaps it's good to force everybody to take a look at this if they can't somehow produce a useful error here; if not, it's still straight-forward enough to do something like maybe (Left "no error info, sorry") Right to the maybe-parser.

Yes, I think it should be a breaking change. @arianvp, @dmjio anybody: any opinions?

test/Test.hs Show resolved Hide resolved
test/Test.hs Show resolved Hide resolved
@fisx
Copy link
Member

fisx commented May 30, 2020

Okay, I've reverted that small change, now it should build on 8.0.
I have another thought: do we really need the "fromMultipart failed:" prefix in the error message? I suppose it should be OK to drop it and return the parser's message verbatim?

The extra prefix could be helpful, depending on how unhelpful the parser is, which depends on the user of the library, so I'm not sure we should depend on it.

Would "Could not decode multipart mime body: <parser error message>" be an improvement? I'd prefer something like this because it does not leak servant internals to the API.

Since the PR is such an obvious improvement either way: if you feel strongly about this and nobody else objects, I'm ok with the change you suggest.

@maksbotan
Copy link
Contributor Author

Hi,

I'm okay with extended message hiding fromMultipart. I'll try to commit it today.

Re breaking changes: I believe there is no need in transition mechanism, let users see this right away and be able to react. Anyway I suppose this will go into major version bump, like 0.12.0.

Re nitpicks: I'll also react to them in a commit today :)

Thanks for the review!

maksbotan added 3 commits May 30, 2020 23:22
This allows users of the library to provide more fine-grained error
messages for their FromMultipart instances.
@maksbotan maksbotan force-pushed the maksbotan/error-message branch 2 times, most recently from 0e10ee4 to 0d0f2a7 Compare May 31, 2020 07:10
@maksbotan
Copy link
Contributor Author

I've rebased the history to make it pretty and incorporated your ideas. Thanks!

Just in case: after this is merged, I'm going to make a PR with regenerated haskell-ci and another one with version bump.

maksbotan added 3 commits June 2, 2020 00:23
Some users may want to process parsing errors in their handlers instead
of relying on servant-multipart's default error response. So we
introduce Lenient mode similar to Capture.
This test suite checks that all modes of decoding work as expected,
without running full warp web server.

Previous test-suite "upload" was converted to an executable, since it is
useless as a test-suite.
@maksbotan maksbotan force-pushed the maksbotan/error-message branch from 0d0f2a7 to 1d7c091 Compare June 1, 2020 21:25
@maksbotan
Copy link
Contributor Author

Ping? :)

@arianvp
Copy link
Member

arianvp commented Jun 4, 2020

i'll try to give this a quick look tomorrow. if I don't then Matthias just should merge this I think

@fisx fisx merged commit 4b15358 into haskell-servant:master Jun 5, 2020
@fisx
Copy link
Member

fisx commented Jun 5, 2020

Thanks again, and sorry for the delay!

Not sure about when we'll make a release. Probably not before zurihac.

@maksbotan
Copy link
Contributor Author

Thanks!

@hsenag hsenag mentioned this pull request Aug 14, 2020
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 this pull request may close these issues.

3 participants