feedforward icon indicating copy to clipboard operation
feedforward copied to clipboard

Crashes on minitidal syntax error

Open ndr-brt opened this issue 4 years ago • 5 comments

e.g. with s "bd<"

it crashes with:

Error in pattern: Syntax error in sequence:
  "bd<"
      ^  
unexpected end of input
expecting white space, charnum, rest, "[", "{", "<", "^", ".", "," or ">"
feedforward: Syntax error in sequence:
  "bd<"
      ^  
unexpected end of input
expecting white space, charnum, rest, "[", "{", "<", "^", ".", "," or ">"

ndr-brt avatar Jan 12 '21 11:01 ndr-brt

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

yaxu avatar Jan 12 '21 11:01 yaxu

Hm so I guess this syntax error comes earlier, otherwise this workaround would take care of it.

yaxu avatar Jan 12 '21 11:01 yaxu

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).

jwaldmann avatar Jan 13 '21 10:01 jwaldmann

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

ndr-brt avatar Jan 18 '21 15:01 ndr-brt

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!

¯_(ツ)_/¯

ndr-brt avatar Feb 19 '21 11:02 ndr-brt