Compilation error while doing a live set

What if you make a mistake while live coding and get a compile error? The music just stops? Is there any way to make it so it just tries compiling and if it fails doesn’t until you’ve fixed the bugs?

Hey @fililou,

It is in fact quite easy to test this: you will notice that if you try something like the following:

live_loop :test1 do
  sample :ambi_lunar_land
  sleep 4
end

live_loop :test2 do
  sample :bd_haus
  sleep 0.5
end

… and then change sleep 0.5 to something like sleep 0.5 / 0 and re-run, you don’t end up with total silence.

(For clarification: when an error occurs, it only stops the thread in which the error occurs - which in this case is the thread belonging to live_loop :test2).
However, If your code on the other hand did not contain any live_loops or in_threads etc, then it essentially only contains one thread, and in that case, then all sound will indeed stop at the error every time until it is fixed.

I believe outright syntax errors are caught before they get a chance to exectue, correct?

But if your error happens at runtime (typoed variable name, division by zero, etc) then it will properly fail. It might be technically possible to statically check for incorrect variable names (and fx/synth names, etc) to protect against some of this. But it is generally not possible to really validate the new code before executing, and potentially failing :frowning:

Just to clarify the previous answers:

  1. There are no “compilation errors” in Sonic Pi - it’s an interpreted system
  2. There are two kinds of errors you can run into: syntax errors (these pop up in blue) and runtime errors (these pop up in pink).
  3. Blue syntax errors mean that there’s a mistake in the code such that it can’t be read. This means that Sonic Pi ignores the code and doesn’t do anything until its fixed. Any existing running code is unaffected.
  4. Pink runtime errors means that one of the threads was asked to do something it couldn’t so it stopped. If you only have one thread running, your entire program stops. If you have more than one thread (live loops are threads) then just the thread with the issue stops and the rest continue.
  5. When performing - always have more than 1 thread running, so a pink runtime error does not stop all the sounds, and you can fix the broken thread and get it going again.

I hope that this helps :slight_smile:

3 Likes