emanote icon indicating copy to clipboard operation
emanote copied to clipboard

Malformed YAML files break Emanote

Open j-steinbach opened this issue 2 years ago • 13 comments

Describe the bug

When starting Emanote I get the error Unable to render template in the browser:

Union mounting notebook layers; please wait ...
Ema App threw an exception
Unable to render template '/templates/error'

Once you fix the source of the error, this page will automatically refresh.

The console says [Error#System.UnionMount] Change handler exception: BadInput "NonStringKey []" after loading/checking all my note files.

To Reproduce Steps to reproduce the behavior:

  1. Start Emanote via emanote or emanote run.
  2. Go to http://127.0.0.1:8000/
  3. Get the error (n the browser)

Expected behavior Not getting the error.

Screenshots

image

Desktop (please complete the following information):

  • Firefox 99.0.1 (64-bit)
  • NixOS unstable (Flake install)
  • emanote --version 0.6.5.4

Additional context Haven't run Emanote for a few weeks/months. This is also a new computer where I copied my old notes folder.

j-steinbach avatar May 07 '22 16:05 j-steinbach

Could you share a Markdown note file that triggers this?

Investigating ...

(Congrats on installing NixOS!)

srid avatar May 07 '22 16:05 srid

I added this to the YAML frontmatter:

image

And that resulted in the live server showing:

image

This is expected behaviour as of b84c3b4161a4bd6bc56765219d4cfe4e15a1a464 ... are you sure you are in fact running 0.6.5.4?

srid avatar May 07 '22 17:05 srid

Both emanote --version and the run log say so

image

j-steinbach avatar May 07 '22 17:05 j-steinbach

Ah, it seems that maybe I ran it in the wrong folder? I have a base directory that contains the meta files from all my notes tools and a single note directory afterwards. I ran the Emanote command in the base directory..

j-steinbach avatar May 07 '22 17:05 j-steinbach

Ah, it seems that maybe I ran it in the wrong folder?

If you could create a repository on GitHub containing the files that trigger this particular issue that would be helpful. Because so far I cannot reproduce this bug on my system.

srid avatar May 07 '22 17:05 srid

Sure, I'll try! But might take a bit

j-steinbach avatar May 07 '22 17:05 j-steinbach

It seems to be related to https://github.com/anishathalye/dotbot. When I delete the /tmp/emanote-test/dotbot/lib folder the error before [Info#ema] Ema live server running: http://127.0.0.1:8000 disappears.


Unfortunately I now I get this error.. (after [Info#ema] Ema live server running: http://127.0.0.1:8000)

[Error#ema.ws.01] Ema: route 'R[/index.md]' encodes to 'index.html' but it is not isomporphic.
[("",["Testing Partial ISO law for R[/index.md] and ","Route's actual encoding: index.html","Decoding of that encoding: Just R[/index.html]","ERR:  /= index.html","ERR: Just R[/index.md] /= Just R[/index.html]"]),(".html",["Testing Partial ISO law for R[/index.md] and .html","Route's actual encoding: index.html","Decoding of that encoding: Just R[/index.html]","ERR: .html /= index.html","ERR: Just R[/index.md] /= Just R[/index.html]"]),("index.html",["Testing Partial ISO law for R[/index.md] and index.html","Route's actual encoding: index.html","Decoding of that encoding: Just R[/index.html]","ERR: Just R[/index.md] /= Just R[/index.html]"])]
You should fix your `RouteEncoder`.

j-steinbach avatar May 07 '22 17:05 j-steinbach

I'm trying to replicate this from a fresh new folder but I don't seem to be able to.. The dotbot install seems to also have changed.

E: Actually makes sense: The dotbot repository also has changed over time. So to reproduce I would have to download an old version of the lib folder..

j-steinbach avatar May 07 '22 17:05 j-steinbach

I can reproduce it. The lib folder actually points to https://github.com/yaml/pyyaml/.

  1. Create empty folder and enter it
  2. git clone https://github.com/yaml/pyyaml/
  3. emanote gen .
  4. Boom!

j-steinbach avatar May 07 '22 17:05 j-steinbach

Great! So the minimal repro is to apply this patch in the Emanote git repo and run bin/run:

diff --git a/docs/index.yaml b/docs/index.yaml
index 13688aa6..e65997f5 100644
--- a/docs/index.yaml
+++ b/docs/index.yaml
@@ -5,3 +5,5 @@ page:
   siteTitle: Emanote
   headHtml: |
     <snippet var="js.prism" />
+
+[]: foo
\ No newline at end of file

srid avatar May 07 '22 18:05 srid

The proper fix here is to handle syntax errors in *.yaml files and display them in the live-server (like we already do for syntax errors in *.md files).[^more] And the meta-fix here is to fix Ema (https://github.com/srid/ema/pull/81) from breaking down when an exception is thrown in a Dynamic handler.

https://github.com/srid/emanote/blob/2b6558fde2999ec22f645cb95322995b780f09f1/src/Emanote/Source/Patch.hs#L100-L101

For now, as a workaround, you can move these dotfiles out of the way, or put them in an actual dot directory (.foo) as Emanote ignores them. I assume these are not critical to your notebook.

[^more]: Unlike the Markdown errors, however, these wouldn't be per-route. So we may also need a global errors page for displaying the full list of errors (equivalent to what the 'gen' command would display in the console).

srid avatar May 07 '22 18:05 srid

Well, they are not dotfiles but instead a tool/script to link/deploy (dot)files to my system. But yes, they are not that important. Also, the tool can be installed as git submodule now, so I can delete the folder anyway.

Overall I think this is a decent workaround :+1: . That means we can close this?

j-steinbach avatar May 07 '22 19:05 j-steinbach

Let's keep it open. I will implement the proper fix stated above when I get to it.

srid avatar May 07 '22 19:05 srid