Viir / Kalmit

Moved to https://github.com/elm-fullstack/elm-fullstack
MIT License
2 stars 0 forks source link

Support inspecting the javascript code #6

Open Viir opened 5 years ago

Viir commented 5 years ago

I got following exception:

start-bot failed with exception: System.Exception: Failed to process bot event. ---> JavaScriptEngineSwitcher.Core.JsRuntimeException: TypeError: Unable to get property 'volatileHost' of undefined or null reference
   at author$project$SimpleSanderling$getNextSetupTask (Script Document:3760:2) ->      var _n0 = stateBefore.volatileHost;
   at Anonymous function (Script Document:4267:4)
   at Anonymous function (Script Document:4266:3)
   at A3 (Script Document:59:3)
   at Anonymous function (Script Document:4386:3)
   at Anonymous function (Script Document:15:47)
   at A2 (Script Document:56:3)
   at Anonymous function (Script Document:3141:5)
   at Anonymous function (Script Document:3131:3)
   at Anonymous function (Script Document:15:47) ---> JavaScriptEngineSwitcher.ChakraCore.JsRt.JsScriptException: Script threw an exception.
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorHelpers.ThrowIfError(JsErrorCode error)
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsContext.RunScript(String script, JsSourceContext sourceContext, String sourceUrl, JsParseScriptAttributes& parseAttributes)
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.<>c__DisplayClass22_0.<InnerEvaluate>b__0()
   --- End of inner exception stack trace ---
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.<>c__DisplayClass22_0.<InnerEvaluate>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.<>c__DisplayClass10_0`1.<Invoke>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.StartThread()
--- End of stack trace from previous location where exception was thrown ---
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(Func`1 del)
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke[T](Func`1 func)
   at Kalmit.ProcessWithCustomSerializationHostedWithPuppeteer.EvaluateInJsEngineAndReturnResultAsString(String expressionJavascript)
   at Kalmit.ProcessWithCustomSerializationHostedWithPuppeteer.ProcessEvent(String serializedEvent)
   at Kalmit.PersistentProcess.PersistentProcessWithHistoryOnFileFromElm019Code.<ProcessEvents>b__5_0(String serializedEvent)

It would be helpful to inspect the javascript code to find out more about this problem. Probably both the javascriptFromElmMake and the final javscript should be available for inspection:

https://github.com/Viir/Kalmit/blob/640078f59bea3fa2ba1af43372933cff304b8c94/implement/PersistentProcess/PersistentProcess.Common/Process.cs#L122-L130

Viir commented 5 years ago

Further investigating the issue leading to the exception shown above: The problem, in that case, was that the functions to init the state and process events used different state types. The error was in the value for pathToInitialStateFunction in this part of the configuration: https://github.com/Viir/Kalmit/blob/640078f59bea3fa2ba1af43372933cff304b8c94/implement/PersistentProcess/PersistentProcess.Common/Process.cs#L104-L111

As I confused different init functions, the type of the actually configured one was wrong. Therefore the value produced there resulted in the crash when calling the event processing function.

To prevent such confusion, the framework should check that these types match and produce an error message if they don't.

Viir commented 5 years ago

The inspection part is now covered with https://github.com/Viir/Kalmit/commit/8a4f2a317cd21dfa857c6851eb10be623c1aaf59