I'm not sure if exception handling is done by the story format or Twine,
but I'm using SugarCube 2.10.0 and compiling with the entwine utility (should be compatible with Twine 2.1).
Unfortunately, debugging Javascript is not very convenient right now inside a Twine story.
Any errors that occur bring up an alert that is not specific enough (does not point to line that's causing the problem).
It also unnecessarily eats up exceptions. If I
throw "some exception"
in the story Javascript, the alert will just say
"unknown error" rather than providing the text of the exception.
I imagine allowing debugging line-by-line might not be technically feasible, but allowing exceptions to pass through should be very dobale. Is there a reason why it's currently like this?
Comments
As far as your exceptions being unknown. Try throwing a proper exception object instead of a string—e.g. Error. For example: Due to the requirements of JavaScript's great and terrible legacy, throw allows you to toss any type of data—e.g. throw true. Do not do this. Use the various exception objects.
The problem persists after switching to the proper way of exception throwing. (unknown error)
I'd settle for less than a stack trace - I'd just like to know the specific error (so in this case, console logging to get specificity + exception to exit would work but I'd have to repeat myself).
I'm using the grunt-entwine tool to compile various sources.
I have a library file da.js that's specified to Grunt before the story javascript file story.js - so in the concatenation of sources the library is placed first.
I expect the exception to be thrown during the processing of story.js, which has a line: In the naked context (not wrapped with on document ready or anything, so as soon as it's encountered).
This should throw in the constructor because at the top of the constructor there is And load() hasn't been called yet.
I also see that the developer is throwing a mishmash of exception objects and strings. I know him, so I'll yell at him about that.
Also. I've gone ahead and updated SugarCube in my local repo to handle non-exception exceptions in most areas where user code may be evaluated. The commit message: It'll be in the next release.
I think the latest DAD build fixes this issue.