flatironinstitute / stan-playground

Run Stan models in the browser
Apache License 2.0
29 stars 1 forks source link

Sampling with an empty Data window causes TypeError #226

Closed jsoules closed 1 week ago

jsoules commented 1 week ago

To reproduce:

Unclear whether this is happening in the front-end or if we're being more tolerant of malformed data than the tinystan back-end is. I do notice that the issue occurs even if the data window string is not completely empty (e.g. contains only a space) and so is not strictly lengthless/null.

Also note, a different error is generated if the data consists only of an empty object ({}).

jsoules commented 1 week ago

The specific error reported varies by browser. In Chrome I have: TypeError: Cannot read properties of undefined (reading 'length')

In Firefox, TypeError: str is undefined

Elsewhere we have reports of: TypeError: undefined is not an object (evaluating 'str.length')

In any event, this appears to relate to a call to check the length of something that is presumed to be a string but is not defined.

The call path is roughly as follows:

Observation 1: a potential front-end fix here is to update the Button via the RunPanel component so that it is disabled if the data parameter is undefined.

Observation 2: It might be worthwhile to have the tinystan code do some existence/type checking of the data parameter before attempting to read it at greater length.

For now, I'm going to go with the solution suggested in Observation 1.