Thanks!  I'll try your version suggestion.  I also understand why I 
couldn't catch the error now too from this 
post: https://groups.google.com/forum/#!topic/elm-discuss/vk4w_Ei8A84

Thanks,
Kevin
(Also, sorry for double posting!)

On Saturday, October 15, 2016 at 5:19:01 PM UTC-4, Peter Damoc wrote:
>
> You can check for a version of the storage schema and patch the data 
> before sending it to Elm (or just drop it). In your case, you could also 
> work with the fact that you know that the new version has comments: 
>
>     <script>
>         const storedState = localStorage.getItem('model');
>         var startingState = storedState ? JSON.parse(storedState) : null;
>         if (! "comment" in startingState) {
>             startingState = null;
>         }
>         try {
>             elmApp = Elm.Main.fullscreen(startingState);
>         }
>         catch (e) {
>             throw "it caught!";
>         }
>         elmApp.ports.setStorage.subscribe(function (state) {
>           localStorage.setItem('model', JSON.stringify(state));
>         })
>     </script>
>
>  
> Alternatively, you could pass the data as Value in your program and use 
> multiple decoders to extract the data but that would be a little bit more 
> complicated. 
>
>
>
> On Thu, Oct 13, 2016 at 10:31 PM, Kevin Berridge <[email protected] 
> <javascript:>> wrote:
>
>> 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 
>> https://medium.com/wunder-nerds/storing-and-restoring-the-state-in-elm-0-17-94874429dc1d#.gmkt7hrwu.
>>   
>> 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.
>>     <script>
>>         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));
>>         })
>>     </script>
>>
>> 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,
>> Kevin
>>
>> -- 
>> 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 to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>

-- 
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 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to