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

nonEmpty validation doesn't work on Int values #1099

Closed
amitaibu opened this issue Oct 2, 2021 · 6 comments
Closed

nonEmpty validation doesn't work on Int values #1099

amitaibu opened this issue Oct 2, 2021 · 6 comments

Comments

@amitaibu
Copy link
Collaborator

amitaibu commented Oct 2, 2021

I have a non nullable Int field, however I cannot add nonEmpty field on it as there's the error Could not deduce (IsEmpty Int) arising from a use of nonEmpty'`

@mpscholten
Copy link
Member

If the int field is empty, the int field parser will fail to parse the empty string and produce an error like this:

image

So i think no nonEmpty is needed in this case. Or do i miss something?

@amitaibu
Copy link
Collaborator Author

amitaibu commented Oct 4, 2021

I have this an in exiting Repo, where the error of validation of the form is that of a sub-record.
Here's the code - https://github.com/amitaibu/ihp-bid/blob/a02ee2860811baf35b591bebf4c44d1e6274be99/Web/Controller/Items.hs#L71

Steps to reproduce

  1. Checkout https://github.com/amitaibu/ihp-bid
  2. Visit http://localhost:8000/NewItem
  3. Add title
  4. Submit form

Current behavior

Selection_999(266)

image

@amitaibu
Copy link
Collaborator Author

amitaibu commented Oct 8, 2021

I was able to find the line that is causing the 'min' is invalid CallStack... and that's getValidationFailure #min bidStep

Still not sure why, I'll try to dig.

@amitaibu
Copy link
Collaborator Author

amitaibu commented Oct 8, 2021

Sorry, it's not that. I'll have to come back to it with fresh eyes, but something is weird 😸

@amitaibu
Copy link
Collaborator Author

amitaibu commented Oct 8, 2021

Seems the error is coming from

ihp/IHP/Controller/Param.hs

Lines 113 to 123 in 6f5f3f9

paramList :: forall valueType. (?context :: ControllerContext, DeepSeq.NFData valueType, ParamReader valueType) => ByteString -> [valueType]
paramList name =
allParams
|> filter (\(paramName, paramValue) -> paramName == name)
|> mapMaybe (\(paramName, paramValue) -> paramValue)
|> map (readParameter @valueType)
|> map (Either.fromRight (error (paramParserErrorMessage name)))
|> DeepSeq.force
{-# INLINABLE paramList #-}
paramParserErrorMessage name = "param: Parameter '" <> cs name <> "' is invalid"

If the value is empty, it throws the error because it gets (min, "")

@amitaibu
Copy link
Collaborator Author

Closing in favor of #1130

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

No branches or pull requests

2 participants