Breaking Change: Calling an API method with undefined throws an error
-
Hi everybody,
after tracking down some weird bugs which were caused by an implicit cast from undefined to 0 because a ParameterId wasn't spelled correctly (or the object was created after the call silently returning
undefined
), I decided to not allow passing undefined into any API calls anymore, so from now on you will get an error like this:API call with undefined parameter 0
This should not break any existing code, because I don't know any scenario where you would want to pass undefined into an API call, but it prevents you from nasty follow up errors.
In my case, I was using a reference to a synth before it was actually created soGroup.UnisonoVoiceAmount
returnedundefined
which set the gain of the module (= Parameter index 0) to zero effectively muting the output of this module.I also added a new function called
isDefined(value)
, which returns false if thevalue
is not defined (orvoid
which is a non-existent key value from an object but practically the same thing). So whenever you hit that error, from now on you can replace the API call with this construct:if(isDefined(value) { Api.someCall(value); } else { // handle the undefined value gracefully instead of silently converting it to zero and causing weird stuff. }