Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[SugarCube 2]Allow Exceptions to Pass for Debugging

edited October 2016 in Help! with 2.0
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

  • edited October 2016
    Depending on where/when exceptions are thrown you may/may not receive a stack trace due to various factors—at least, if you're throwing proper exceptions. Though, a stack trace from user code is unlikely to be especially helpful, due to the nature of how the system works.

    As far as your exceptions being unknown. Try throwing a proper exception object instead of a string—e.g. Error. For example:
    throw new Error("Guru Meditation Error!");
    
    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.
  • edited October 2016
    Hi TME,
    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).
  • Where are you, specifically, throwing these exceptions?
  • edited October 2016
    Presumably in a function call somewhere in Story Javascript.
    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:
    var player = new da.Player();
    
    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
                if (da.loaded === false) {
                    throw new Error("trying to create Player without having loaded first! (call da.load() before)");
                }
    
    And load() hasn't been called yet.
  • I'm going to assume that you're referring to the Dynamic Avatar Drawer and you're using a recent version. The code you've referenced is not within the constructor for da.Player, but rather the da.draw() static method, so you should not see it simply by instantiating a new Player.

    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:
    Updated the user script and widget loading code and all macros which evaluate code to be able to handle values which are not exception objects; i.e. from crappy code that throws strings and the like.
    It'll be in the next release.
  • Haha all right,
    I think the latest DAD build fixes this issue.
Sign In or Register to comment.