gpt4 book ai didi

Scala.js 堆栈跟踪

转载 作者:行者123 更新时间:2023-12-04 15:07:26 26 4
gpt4 key购买 nike

当我的 Scala.js 代码抛出异常时,我对难以理解的堆栈跟踪感到沮丧。我以为我有一个使用 Javascript 库的解决方案(请参阅 Getting a scala stacktrace ),但它经常中断。

您如何从如下所示的堆栈跟踪中提取含义(程序中断的地方;它是如何到达那里的——就 Scala 代码而言)。或者我做错了什么以获得未翻译的堆栈跟踪?

Sample Scala.js stacktrace

最佳答案

看看我在你的框架中写的这段代码:https://github.com/outr/youi/tree/e66dc36a12780fa8941152d07de9c3a52d28fc10/app/js/src/main/scala/io/youi/app/sourceMap

它用于将 JS 堆栈跟踪反转为 Scala 堆栈跟踪。在 youi 中,我将错误发送到服务器,以便我可以监视完整回溯中发生的浏览器错误。

简要概述

  • source-map.js

  • You need source-map.js to parse the js.map file that Scala.js generated when it compiled your code. See: https://github.com/mozilla/source-map


  • 通过ajax加载js.map文件

  • The SourceMapConsumer needs a js.Object (JSON) of the js.map file. See https://github.com/outr/youi/blob/e66dc36a12780fa8941152d07de9c3a52d28fc10/app/js/src/main/scala/io/youi/app/sourceMap/ErrorTrace.scala#L58 for an example of loading via youi's Ajax features.


  • 处理 Throwable

  • The trace represents line and columns in the JS file and you can pass that information to SourceMapConsumer to get the original Scala line numbers back (see SourceMapConsumer.originalPositionFor). See ErrorTrace.toCause (https://github.com/outr/youi/blob/e66dc36a12780fa8941152d07de9c3a52d28fc10/app/js/src/main/scala/io/youi/app/sourceMap/ErrorTrace.scala#L98) for an example iterating over the Throwable's trace elements.


  • 处理错误

  • Now that you have the capacity to process JavaScript errors and convert them back to Scala traces, you need to actually receive the errors. If you want to globally handle uncaught errors set a function to window.onerror to capture errors. As of this writing, the function signature in Scala.js isn't ideal for handling all information, so in youi I use js.Dynamic to set it to what I need (see: https://github.com/outr/youi/blob/e66dc36a12780fa8941152d07de9c3a52d28fc10/app/js/src/main/scala/io/youi/app/ClientApplication.scala#L35). Also, notice that in ErrorTrace it supports multiple incoming types of errors (ErrorEvent, Throwable, and a more generic scenario). This is because in JavaScript the errors come in different ways based on what's happening. This is a fairly complex topic, and why I created this functionality in youi to simplify things.



    没有我想要的那么简短的概述,但这不是一个要解决的简单问题。 source-map GitHub 项目 ( https://github.com/mozilla/source-map ) 有不错的文档,是我最初用来编写解决方案的文件(添加了一些试验和错误)。如果我提供的信息不完整,我建议在那里阅读更多内容,因为它应该提供大部分信息,并且可能会得到更好的解释。

    关于Scala.js 堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103006/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com