You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a runtime exception is caused in the subscribe function in js (such as calling an undefined function), commands are no longer being issued and subscriptions are ignored.
SSCCE
port moduleMainexposing (main)
importBrowserimportHtmlexposing (Html, button, div, text)
importHtml.Eventsexposing (onClick)
importTimetype alias Model={ time :Time.Posix}initialModel:ModelinitialModel ={ time =Time.millisToPosix 0}type Msg=GotTimeTime.Posix|ClickedCreateRuntimeExceptionInSubscribeupdate:Msg->Model-> ( Model, Cmdmsg )
update msg model =case msg ofGotTime time ->({ model | time = time },Cmd.none )ClickedCreateRuntimeExceptionInSubscribe->( model, createRuntimeExceptionInSubscribe ())view:Model->HtmlMsgview model =
div [][ div [][ text <|String.fromInt <|Time.toHour Time.utc model.time
, text ":", text <|String.fromInt <|Time.toMinute Time.utc model.time
, text ":", text <|String.fromInt <|Time.toSecond Time.utc model.time
], button [ onClick ClickedCreateRuntimeExceptionInSubscribe][ text "create runtime exception in subscribe"]]port createRuntimeExceptionInSubscribe:()->Cmdmsgmain:Program()ModelMsgmain =Browser.element
{ init =\_ ->( initialModel,Cmd.none ), view = view
, update = update
, subscriptions =\_ ->Time.every 1000GotTime}
Will wrapping this in a try...catch block solve the problem? Have the catch block emmit an error message to the console if any unhandled exception falls through.
Another suggestion is to always use async:
myPort.subscribe(async (value) => {
stuff();
});
Can the Elm runtime always invoke the callback with async?
Which solution is better? Happy to make a PR for one.
If a runtime exception is caused in the subscribe function in js (such as calling an undefined function), commands are no longer being issued and subscriptions are ignored.
SSCCE
Expected
Subscriptions still update the model and cmds can still be issued through update.
Actual
Model can still be updated by user interactions, but subscriptions don't do anything and user interactions have no side effects.
The text was updated successfully, but these errors were encountered: