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

Uninitialized SiteContents being passed to post generator in watch mode #96

Closed
rdipardo opened this issue Jun 24, 2021 · 1 comment · Fixed by #103
Closed

Uninitialized SiteContents being passed to post generator in watch mode #96

rdipardo opened this issue Jun 24, 2021 · 1 comment · Fixed by #103

Comments

@rdipardo
Copy link
Contributor

Describe the bug

Changing a Markdown file in watch mode makes the generators/post.fsx script throw an unhandled KeyNotFoundException.

The reason seems to be that an empty instance of SiteContents is being passed to the script.
Strangely, the first generation cycle runs to completion without a problem.

To Reproduce

  1. Clone the source tree
  2. Add a debug message showing the value of the SiteContents argument before Seq.find gets called in generators/post.fsx, e.g.:
let generate' (ctx : SiteContents) (page: string) =
    let allPosts =
        ctx.TryGetValues<Postloader.Post> ()
        |> Option.defaultValue Seq.empty

    eprintfn "%O has %d posts" ctx (Seq.length allPosts)

    let post =
        allPosts
        |> Seq.find (fun n -> n.file = page)
  1. Build the demo project:

     dotnet tool restore
     dotnet fake build -t TestTemplate
    
  2. The initial build finishes with output like this:

Starting target 'TestTemplate'
[...snip...]
[23:09:34] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/post3.html' generated in 1ms
[23:09:34] '/home/rob/dev/Fornax/src/Fornax.Template/_public/js/sampleJsFile.js' generated in 106ms
[23:09:34] '/home/rob/dev/Fornax/src/Fornax.Template/_public/images/avatar.jpg' generated in 1ms
[23:09:34] '/home/rob/dev/Fornax/src/Fornax.Template/_public/images/bulma.png' generated in 1ms
[23:09:34] '/home/rob/dev/Fornax/src/Fornax.Template/_public/images/favicon.png' generated in 0ms
[23:09:34] '/home/rob/dev/Fornax/src/Fornax.Template/_public/style/style.css' generated in 1ms
Model+SiteContents has 7 posts
[23:09:34] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/subdir/post3.html' generated in 2ms
Generation time: 00:00:23.1454396
[23:09:35] Watch mode started. Press any key to exit.
[23:09:35 INF] Smooth! Suave listener started in 138.573ms with binding 127.0.0.1:8080
  1. With watch mode running, edit a Markdown file, e.g.:
echo -e "\n\n### More\n" >> src/Fornax.Template/posts/post.md
  1. Notice that the SiteContents argument now contains no post data, crashing the build:
[23:09:45] Changes detected: /home/rob/dev/Fornax/src/Fornax.Template/posts/post.md
[23:09:48] multiple files generated in 638ms
[23:09:48] '/home/rob/dev/Fornax/src/Fornax.Template/_public/about.html' generated in 1ms
[23:09:48] '/home/rob/dev/Fornax/src/Fornax.Template/_public/contact.html' generated in 1ms
Model+SiteContents has 0 posts
An unexpected error happend: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Collections.Generic.KeyNotFoundException: An index satisfying the predicate was not found in the collection.
   at Microsoft.FSharp.Collections.SeqModule.Find[T](FSharpFunc`2 predicate, IEnumerable`1 source) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 677
   at FSI_0022.Post.generate'(SiteContents ctx, String page)
   at lambda_method21(Closure , Unit , SiteContents , String , String )
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Generator.EvaluatorHelpers.helper@56(Object next, FSharpList`1 args) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 66
   at Generator.EvaluatorHelpers.invokeFunction(Object f, IEnumerable`1 args) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 70
   at [email protected](Object generator) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 195
   at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
   at Generator.GeneratorEvaluator.evaluate(FsiEvaluationSession fsi, SiteContents siteContent, String generatorPath, String projectRoot, String page) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 190
   at Generator.generate(FsiEvaluationSession fsi, Config cfg, SiteContents siteContent, String projectRoot, String page) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 333
   at Generator.action@1-3(String projectRoot, FsiEvaluationSession fsi, Config config, SiteContents sc, String filePath) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 496
   at Generator.generateFolder(String projectRoot, Boolean isWatch) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 495
   at Fornax.guardedGenerate@226(String cwd, Unit unitVar0) in /home/rob/dev/Fornax/src/Fornax/Fornax.fs:line 228
Finished (Failed) 'TestTemplate' in 00:00:38.2120491

Expected behaviour

Watch mode should work.

Environment (please complete the following information):

  • OS: Debian 10.5
  • Ionide version: 5.5.7
  • VSCode version: 1.57.1
  • dotnet SDK version: 5.0.301
  • mono / .Net Framework version: Mono JIT compiler version 5.18.0.240 (Debian 5.18.0.240+dfsg-3)

Additional context

This issue probably has the same underlying cause as #84

@Freymaurer
Copy link
Contributor

Same issue here 👍

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