Is there a way to catch the "You are trying to initialize module `Main` 
with an unexpected argument." error when calling Elm.Main.fullscreen({}) 
with out of date arguments?  I tried wrapping it in a try/catch, but the 
catch is not running.

What I'm really trying to do is pass in state that was persisted in local 
storage as described here
 But I changed my model, so now it errors.  I'm happy to just forget the 
state and start over when that happens, so if I could catch the error in JS 
I could do that.

Here's the JS I'm using.  The throw in that catch block doesn't run.
        const storedState = localStorage.getItem('model');
        const startingState = storedState ? JSON.parse(storedState) : null;
        try {
            elmApp = Elm.Main.fullscreen(startingState);
        catch (e) {
            throw "it caught!";
        elmApp.ports.setStorage.subscribe(function (state) {
          localStorage.setItem('model', JSON.stringify(state));

And the JS error that is being thrown (but not being caught) is:
Uncaught Error: You are trying to initialize module `Main` with an 
unexpected argument.
When trying to convert it to a usable Elm value, I run into this problem:

I ran into the following problems:

Expecting null but instead got: {...}
Expecting an object with a field named `comment` at _.distractions[4] but 
instead got: {...}

I truncated the object properties in that message.  That error is correct, 
'comment' was added to my elm model and therefore does not exist in the 
previously stored state that it is trying to deserialize.

Thanks in advance,

You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
For more options, visit

Reply via email to