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

Add paramListOrNothing function #1130

Merged
merged 7 commits into from
Oct 12, 2021

Conversation

amitaibu
Copy link
Collaborator

Trying to address #1099 (comment)

I have followed https://github.com/digitallyinduced/ihp/blob/5f9f65ae272a9a3d1c8c89c0ce5cfe2391ad057c/CONTRIBUTING.md but facing an error upon compilation, so I could use some help here 😅

image

IHP/Controller/Param.hs Outdated Show resolved Hide resolved
IHP/Controller/Param.hs Outdated Show resolved Hide resolved
@mpscholten
Copy link
Member

The type errors comes from changes to the Schema Compiler, basically the build/Generated/Types.hs is outdated.

Try to run this:

ghci
:l IHP/IHP/SchemaCompiler.hs
compile

After this the error should be gone

@amitaibu
Copy link
Collaborator Author

:l IHP/IHP/SchemaCompiler.hs compiles

IHP> :l IHP/IHP/SchemaCompiler.hs [ 1 of 16] Compiling IHP.HaskellSupport ( IHP/IHP/HaskellSupport.hs, interpreted ) [ 2 of 16] Compiling IHP.Log.Types ( IHP/IHP/Log/Types.hs, interpreted ) [ 3 of 16] Compiling IHP.Log ( IHP/IHP/Log.hs, interpreted ) [ 4 of 16] Compiling IHP.NameSupport.Inflections.Data ( IHP/IHP/NameSupport/Inflections/Data.hs, interpreted ) [ 5 of 16] Compiling IHP.NameSupport.Inflections ( IHP/IHP/NameSupport/Inflections.hs, interpreted ) [ 6 of 16] Compiling IHP.NameSupport ( IHP/IHP/NameSupport.hs, interpreted ) [ 7 of 16] Compiling IHP.Postgres.Inet ( IHP/IHP/Postgres/Inet.hs, interpreted ) [ 8 of 16] Compiling IHP.Postgres.Point ( IHP/IHP/Postgres/Point.hs, interpreted ) [ 9 of 16] Compiling IHP.Postgres.TypeInfo ( IHP/IHP/Postgres/TypeInfo.hs, interpreted ) [10 of 16] Compiling IHP.Postgres.TSVector ( IHP/IHP/Postgres/TSVector.hs, interpreted ) [11 of 16] Compiling IHP.ModelSupport ( IHP/IHP/ModelSupport.hs, interpreted ) [12 of 16] Compiling IHP.Prelude ( IHP/IHP/Prelude.hs, interpreted ) [13 of 16] Compiling IHP.IDE.SchemaDesigner.Types ( IHP/IHP/IDE/SchemaDesigner/Types.hs, interpreted ) [14 of 16] Compiling IHP.IDE.SchemaDesigner.Parser ( IHP/IHP/IDE/SchemaDesigner/Parser.hs, interpreted ) [15 of 16] Compiling IHP.IDE.SchemaDesigner.Compiler ( IHP/IHP/IDE/SchemaDesigner/Compiler.hs, interpreted ) [16 of 16] Compiling IHP.SchemaCompiler ( IHP/IHP/SchemaCompiler.hs, interpreted )

IHP/IHP/SchemaCompiler.hs:50:14: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: PTrigger
|
50 | atomicType = \case
| ^^^^^...

IHP/IHP/SchemaCompiler.hs:321:9: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative:
Patterns not matched:
Just (StatementCreateTable _)
Just (CreateEnumType _ _)
Just (CreateExtension _ _)
Just (UnknownStatement _)
...
|
321 | case find isFkConstraint statements of
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

IHP/IHP/SchemaCompiler.hs:331:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for `compileEnumDataDefinitions':
Patterns not matched:
StatementCreateTable _
CreateExtension _ _
AddConstraint _ _ _
UnknownStatement _
...
|
331 | compileEnumDataDefinitions CreateEnumType { values = [] } = "" -- Ignore enums without any values
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

IHP/IHP/SchemaCompiler.hs:503:28: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative:
Patterns not matched:
CreateEnumType _ _
CreateExtension _ _
AddConstraint _ _ _
UnknownStatement _
...
|
503 | |> \case StatementCreateTable CreateTable { columns } -> columns
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ok, 16 modules loaded.

However then I try to :l Main and I get the same error

IHP> :l Main [ 1 of 128] Compiling IHP.HSX.Parser ( IHP/IHP/HSX/Parser.hs, interpreted ) [ 2 of 128] Compiling IHP.HaskellSupport ( IHP/IHP/HaskellSupport.hs, interpreted ) [ 3 of 128] Compiling IHP.Log.Types ( IHP/IHP/Log/Types.hs, interpreted ) [ 4 of 128] Compiling IHP.Log ( IHP/IHP/Log.hs, interpreted ) [ 5 of 128] Compiling IHP.NameSupport.Inflections.Data ( IHP/IHP/NameSupport/Inflections/Data.hs, interpreted ) [ 6 of 128] Compiling IHP.NameSupport.Inflections ( IHP/IHP/NameSupport/Inflections.hs, interpreted ) [ 7 of 128] Compiling IHP.NameSupport ( IHP/IHP/NameSupport.hs, interpreted ) [ 8 of 128] Compiling IHP.Postgres.Inet ( IHP/IHP/Postgres/Inet.hs, interpreted ) [ 9 of 128] Compiling IHP.Postgres.Point ( IHP/IHP/Postgres/Point.hs, interpreted ) [ 10 of 128] Compiling IHP.Postgres.TypeInfo ( IHP/IHP/Postgres/TypeInfo.hs, interpreted ) [ 11 of 128] Compiling IHP.Postgres.TSVector ( IHP/IHP/Postgres/TSVector.hs, interpreted ) [ 12 of 128] Compiling IHP.ModelSupport ( IHP/IHP/ModelSupport.hs, interpreted ) [ 13 of 128] Compiling IHP.Prelude ( IHP/IHP/Prelude.hs, interpreted ) [ 14 of 128] Compiling IHP.Pagination.Types ( IHP/IHP/Pagination/Types.hs, interpreted ) [ 15 of 128] Compiling IHP.Pagination.Helpers ( IHP/IHP/Pagination/Helpers.hs, interpreted ) [ 16 of 128] Compiling IHP.PageHead.Types ( IHP/IHP/PageHead/Types.hs, interpreted ) [ 17 of 128] Compiling IHP.PGNotify ( IHP/IHP/PGNotify.hs, interpreted ) [ 18 of 128] Compiling IHP.Modal.Types ( IHP/IHP/Modal/Types.hs, interpreted ) [ 19 of 128] Compiling IHP.Mail.Types ( IHP/IHP/Mail/Types.hs, interpreted ) [ 20 of 128] Compiling IHP.LoginSupport.Types ( IHP/IHP/LoginSupport/Types.hs, interpreted ) [ 21 of 128] Compiling IHP.LibDir ( IHP/IHP/LibDir.hs, interpreted ) [ 22 of 128] Compiling IHP.Job.Dashboard.Utils ( IHP/IHP/Job/Dashboard/Utils.hs, interpreted ) [ 23 of 128] Compiling IHP.FlashMessages.Types ( IHP/IHP/FlashMessages/Types.hs, interpreted ) [ 24 of 128] Compiling IHP.FileStorage.Types ( IHP/IHP/FileStorage/Types.hs, interpreted ) [ 25 of 128] Compiling IHP.FileStorage.Preprocessor.ImageMagick ( IHP/IHP/FileStorage/Preprocessor/ImageMagick.hs, interpreted ) [ 26 of 128] Compiling IHP.FileStorage.MimeTypes ( IHP/IHP/FileStorage/MimeTypes.hs, interpreted ) [ 27 of 128] Compiling IHP.Environment ( IHP/IHP/Environment.hs, interpreted ) [ 28 of 128] Compiling IHP.AuthSupport.View.Sessions.New ( IHP/IHP/AuthSupport/View/Sessions/New.hs, interpreted ) [ 29 of 128] Compiling IHP.AuthSupport.Lockable ( IHP/IHP/AuthSupport/Lockable.hs, interpreted ) [ 30 of 128] Compiling IHP.AuthSupport.Authorization ( IHP/IHP/AuthSupport/Authorization.hs, interpreted ) [ 31 of 128] Compiling IHP.AuthSupport.Authentication ( IHP/IHP/AuthSupport/Authentication.hs, interpreted ) [ 32 of 128] Compiling IHP.Assets.Types ( IHP/IHP/Assets/Types.hs, interpreted ) [ 33 of 128] Compiling IHP.Router.Types ( IHP/IHP/Router/Types.hs, interpreted ) [ 34 of 128] Compiling IHP.ValidationSupport.Types ( IHP/IHP/ValidationSupport/Types.hs, interpreted ) [ 35 of 128] Compiling IHP.ValidationSupport.ValidateField ( IHP/IHP/ValidationSupport/ValidateField.hs, interpreted )

IHP/IHP/ValidationSupport/ValidateField.hs:111:5: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: FailureHtml _
|
111 | case validator value of
| ^^^^^^^^^^^^^^^^^^^^^^^...
[ 36 of 128] Compiling IHP.View.Classes ( IHP/IHP/View/Classes.hs, interpreted )
[ 37 of 128] Compiling IHP.View.ConvertibleStrings ( IHP/IHP/View/ConvertibleStrings.hs, interpreted )
[ 38 of 128] Compiling IHP.HSX.ToHtml ( IHP/IHP/HSX/ToHtml.hs, interpreted )
[ 39 of 128] Compiling IHP.QueryBuilder ( IHP/IHP/QueryBuilder.hs, interpreted )

IHP/IHP/QueryBuilder.hs:128:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for `negateFilterOperator':
Patterns not matched:
NotEqOp
NotInOp
IsNotOp
NotLikeOp _
|
128 | negateFilterOperator EqOp = NotEqOp
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
[ 40 of 128] Compiling IHP.Fetch ( IHP/IHP/Fetch.hs, interpreted )
[ 41 of 128] Compiling IHP.ValidationSupport.ValidateIsUnique ( IHP/IHP/ValidationSupport/ValidateIsUnique.hs, interpreted )
[ 42 of 128] Compiling IHP.ValidationSupport.ValidateCanView ( IHP/IHP/ValidationSupport/ValidateCanView.hs, interpreted )
[ 43 of 128] Compiling IHP.ValidationSupport ( IHP/IHP/ValidationSupport.hs, interpreted )
[ 44 of 128] Compiling IHP.FetchRelated ( IHP/IHP/FetchRelated.hs, interpreted )
[ 45 of 128] Compiling IHP.HSX.QQ ( IHP/IHP/HSX/QQ.hs, interpreted )
[ 46 of 128] Compiling IHP.View.TimeAgo ( IHP/IHP/View/TimeAgo.hs, interpreted )
[ 47 of 128] Compiling IHP.View.Types ( IHP/IHP/View/Types.hs, interpreted )
[ 48 of 128] Compiling IHP.View.CSSFramework ( IHP/IHP/View/CSSFramework.hs, interpreted )
[ 49 of 128] Compiling IHP.FrameworkConfig ( IHP/IHP/FrameworkConfig.hs, interpreted )
[ 50 of 128] Compiling IHP.ScriptSupport ( IHP/IHP/ScriptSupport.hs, interpreted )
[ 51 of 128] Compiling IHP.Mail ( IHP/IHP/Mail.hs, interpreted )
[ 52 of 128] Compiling IHP.Job.Types ( IHP/IHP/Job/Types.hs, interpreted )
[ 53 of 128] Compiling IHP.Controller.RequestContext ( IHP/IHP/Controller/RequestContext.hs, interpreted )
[ 54 of 128] Compiling IHP.AutoRefresh.Types ( IHP/IHP/AutoRefresh/Types.hs, interpreted )
[ 55 of 128] Compiling IHP.Controller.Context ( IHP/IHP/Controller/Context.hs, interpreted )
[ 56 of 128] Compiling IHP.PageHead.ControllerFunctions ( IHP/IHP/PageHead/ControllerFunctions.hs, interpreted )
[ 57 of 128] Compiling IHP.PageHead.ViewFunctions ( IHP/IHP/PageHead/ViewFunctions.hs, interpreted )
[ 58 of 128] Compiling IHP.Modal.ViewFunctions ( IHP/IHP/Modal/ViewFunctions.hs, interpreted )
[ 59 of 128] Compiling IHP.Controller.Session ( IHP/IHP/Controller/Session.hs, interpreted )
[ 60 of 128] Compiling IHP.FlashMessages.ControllerFunctions ( IHP/IHP/FlashMessages/ControllerFunctions.hs, interpreted )
[ 61 of 128] Compiling IHP.Controller.Param ( IHP/IHP/Controller/Param.hs, interpreted )
[ 62 of 128] Compiling IHP.Pagination.ControllerFunctions ( IHP/IHP/Pagination/ControllerFunctions.hs, interpreted )
[ 63 of 128] Compiling IHP.Job.Queue ( IHP/IHP/Job/Queue.hs, interpreted )
[ 64 of 128] Compiling Generated.Types ( build/Generated/Types.hs, interpreted )

build/Generated/Types.hs:132:16: error:
Not in scope: type constructor or class `PrimaryKeyCondition'
|
132 | instance () => PrimaryKeyCondition (BidStep' itemId) where
| ^^^^^^^^^^^^^^^^^^^

build/Generated/Types.hs:225:16: error:
Not in scope: type constructor or class `PrimaryKeyCondition'
|
225 | instance () => PrimaryKeyCondition (User' ) where
| ^^^^^^^^^^^^^^^^^^^

build/Generated/Types.hs:315:16: error:
Not in scope: type constructor or class `PrimaryKeyCondition'
|
315 | instance () => PrimaryKeyCondition (Item' bidSteps bids) where
| ^^^^^^^^^^^^^^^^^^^

build/Generated/Types.hs:418:16: error:
Not in scope: type constructor or class `PrimaryKeyCondition'
|
418 | instance () => PrimaryKeyCondition (Bid' itemId bidJobs) where
| ^^^^^^^^^^^^^^^^^^^

build/Generated/Types.hs:536:16: error:
Not in scope: type constructor or class `PrimaryKeyCondition'
|
536 | instance () => PrimaryKeyCondition (BidJob' bidId) where
| ^^^^^^^^^^^^^^^^^^^
Failed, 63 modules loaded.

@mpscholten
Copy link
Member

Did you run the compile function?

@amitaibu
Copy link
Collaborator Author

Oops, I missed that - works now! I'll try to add some tests...

@amitaibu
Copy link
Collaborator Author

Did you run the compile function?

btw, worth probably adding that to the Contribution?

I'm still unable to get hspec to work. In fact I've spinned of a GitPod.io workspace, added hspec to default.nix ran make -B .envrc. However it still doesn't recognize hspec command

@mpscholten You should have access to it - https://indigo-ostrich-lcv17mqs.ws-eu18.gitpod.io/

@mpscholten
Copy link
Member

btw, worth probably adding that to the Contribution?

Yes, we could add it 👍 Best to add it to the Troubleshooting section there ("Type errors in build/Generated/Types.hs"). The error only happens when we have B.C. breaks in some of the interfaces, which doesn't happen very often.

I'm still unable to get hspec to work. In fact I've spinned of a GitPod.io workspace, added hspec to default.nix ran make -B .envrc. However it still doesn't recognize hspec command

To run the IHP tests:

cd IHP
nix-shell
ghci
:l Test/Main
main

# after you made some changes
:r
main

@amitaibu
Copy link
Collaborator Author

Errors on :l Test/Main

Selection_999(321)

@mpscholten
Copy link
Member

Try the suggested fix in the warning there. That should fix it :)

@amitaibu
Copy link
Collaborator Author

I have :set -XPackageImports on ghci but now there are more errors. Am I'm doing something wrong here? 😸

Selection_999(322)

@mpscholten
Copy link
Member

I meant the WARNING: .ghci is writable by someone else, IGNORING! error :) (it's in the above screenshot when you started ghci)

Try running chmod go-w .ghci as suggested

@amitaibu
Copy link
Collaborator Author

Haha, so many newbie mistakes 🤕
It's now working!

@mpscholten
Copy link
Member

Perfect :) no worries!

describe "paramListOrNothing" do
it "should parse valid input" do
let ?context = createControllerContextWithParams [("ingredients", "milk"), ("ingredients", ""), ("ingredients", "egg")]
(paramListOrNothing @Text "ingredients") `shouldBe` [Just "milk", Just "", Just "egg"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you think Just "" is correct here, or would you expect it to be Nothing (since value is empty)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO for empty text it should Nothing, but wasn't sure :)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's consistent with paramOrNothin 👍

@amitaibu amitaibu changed the title WIP: Add paramListOrNothing function Add paramListOrNothing function Oct 12, 2021
@amitaibu amitaibu marked this pull request as ready for review October 12, 2021 11:18
Copy link
Member

@mpscholten mpscholten left a comment

Choose a reason for hiding this comment

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

Perfect, good job :)

@mpscholten mpscholten merged commit 788c2af into digitallyinduced:master Oct 12, 2021
@amitaibu amitaibu deleted the paramListOrNothing branch October 12, 2021 13:03
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.

2 participants