ihp icon indicating copy to clipboard operation
ihp copied to clipboard

IHP requires restart after generating new Controller

Open themmes opened this issue 3 years ago • 4 comments

Hi, its me again trying to push forward a model containing floats ;-)!

Steps to reproduce

  1. ihp-new test
  2. cd test and ./start
  3. create new table in schema designer
  4. update and push to db
  5. create new codegen/Controller for that table

Expected

Successful compilation similar to the example with "Posts"

Bug

received Compilation error due to missing references, which is resolved by restarting IHP

Web/Controller/ProjectProducts.hs:6:1
    Could not find module ‘Web.View.ProjectProducts.Edit’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
6 | import Web.View.ProjectProducts.Edit
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

themmes avatar Aug 08 '20 10:08 themmes

This might be some kind of race condition :) I cannot reproduce the issue, but I believe that this indeed can occur.

I think this is caused by the generators plan order in executePlan.

The code generation plan for a controller looks like:

        [ CreateFile { filePath = applicationName <> "/Controller/" <> controllerName <> ".hs", fileContent = (generateController schema config) }
        , AppendToFile { filePath = applicationName <> "/Routes.hs", fileContent = (controllerInstance config) }
        , AppendToFile { filePath = applicationName <> "/Types.hs", fileContent = (generateControllerData config) }
        , AppendToMarker { marker = "-- Controller Imports", filePath = applicationName <> "/FrontController.hs", fileContent = ("import " <> applicationName <> ".Controller." <> controllerName) }
        , AppendToMarker { marker = "-- Generator Marker", filePath = applicationName <> "/FrontController.hs", fileContent = ("        , parseRoute @" <> controllerName <> "Controller") }
        ]
        <> viewPlans

When executePlan did the first step (which creates the Controller file), a reload might already be triggered. But at that point the views are not generated yet. The views will be generated at the end once everything else is done.

So basically what IHP is doing:

Create Web/Controller/ProjectProducts.hs with all the view imports already
Reload Dev Server
Create View File Web/View/ProjectProducts/New.hs
Create View File Web/View/ProjectProducts/....hs

A better plan fixing this issue would look like:

Create View File Web/View/ProjectProducts/New.hs
Reload Dev Server
Create View File Web/View/ProjectProducts/....hs
Reload Dev Server
Create Web/Controller/ProjectProducts.hs with all the view imports already
Reload Dev Server

mpscholten avatar Sep 06 '20 11:09 mpscholten

@mpscholten This seems to still exist as an issue, I have this happening on a brand new project. It also seems that when this occurs, the steps are not fully executed, for example: FrontController.hs was not updated among other files. For reference, I used the dashboard codegen to generate things and it completed "successfully".

jamesrweb avatar Nov 27 '22 15:11 jamesrweb

@jamesrweb when the files are not fully updated, this seems like a new kind of issue. Was there any error before that in the console output?

mpscholten avatar Nov 28 '22 07:11 mpscholten

@jamesrweb when the files are not fully updated, this seems like a new kind of issue. Was there any error before that in the console output?

No, nothing at all except the same message @themmes saw to use -v.

The dashboard said everything was successful as I mentioned, only compile / runtime caught the issue as I said.

I ended up having to manually do the generator steps in the end.

jamesrweb avatar Nov 28 '22 08:11 jamesrweb