Open ndr-brt opened 3 years ago
Right, @jwaldmann made a workaround for this that rolls back to a previous pattern when a runtime error is caught: https://github.com/tidalcycles/Tidal/blob/main/src/Sound/Tidal/Stream.hs#L362-L366
Hm so I guess this syntax error comes earlier, otherwise this workaround would take care of it.
It's difficult to catch exceptions in pure code, because it's evaluated lazily. Exceptions may occur very late (when the value is forced) so they may escape a handler at the place of definition. One has to put a handler where the value is used, or force evaluation where it is defined (if that has a handler).
Interesting, I was doing some trials on the branch of #21 (because there I catch the exception thrown by interpret
).
Adding the putStrLn ar row 81:
https://github.com/ndr-brt/feedforward/blob/bfe5d33e54b587259fc22d5ad9bf9ed3a6eef303/src/TidalHint.hs#L81
Makes the interpreter reload after a mininotation error, so the editor stays up & running. Without that comment, it crashes...
Dunno why, but I think that PR can be merged now
Ok the problem is quite strange, I will try to explain what I noticed debugging...
When code with a pattern with wrong syntax like s "bd<"
is evaluated, the expression:
https://github.com/yaxu/feedforward/blob/dc82d3f0e70a95cdc7ba9f21bd190fa305d4b564/src/TidalHint.hs#L56
Returns Right
, like if it's a correct ControlPattern
.
Then it breaks when it's sent to tidal here
https://github.com/yaxu/feedforward/blob/dc82d3f0e70a95cdc7ba9f21bd190fa305d4b564/src/Edit.hs#L128
( I noticed that catch
here is useless, because there's already a catch
inside streamReplace
:
https://github.com/tidalcycles/Tidal/blob/ff1d6192a073a345075a274b1e918a61157e5043/src/Sound/Tidal/Stream.hs#L524)
As @jwaldmann stated, it's evaluated lazily, so it's impossible to catch inside feedforward, unless there's a possibility to check patterns synchronously before evaluation (maybe called where deltaMini
is called).
I noticed an interesting behaviour with a modification. If this line: https://github.com/yaxu/feedforward/blob/dc82d3f0e70a95cdc7ba9f21bd190fa305d4b564/src/TidalHint.hs#L62 is substituted with
hPutStrLn stderr $ "Eval " ++ show pat
feedforward doesn't crash, but it "restarts" the interpreter (maybe because). I think because show pat
throws an exception, but I'm not able to catching it!
¯_(ツ)_/¯
e.g. with
s "bd<"
it crashes with: