Breaking Change: Calling an API method with undefined throws an error


  • administrators

    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 so Group.UnisonoVoiceAmount returned undefined 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 the value is not defined (or void 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.
    }
    

Log in to reply
 

1
Online

277
Users

739
Topics

4.8k
Posts

Looks like your connection to Forum was lost, please wait while we try to reconnect.