如何在 Firefox 中调试错误的 SVG 解析? (即错误控制台中的“意外值 X 解析 Y 属性”)

发布于 2024-12-05 06:06:27 字数 596 浏览 2 评论 0原文

摘要:

我想查看更详细的 XML/SVG 解析错误消息。我想知道错误发生在哪里。我该怎么做?

背景:

我正在 Firefox 中处理一些复杂的 javascript 生成的 SVG。在我开发过程中,有时在寻找一个大的问题时,我会在 Firefox 错误控制台(或 firebug)中看到错误“Unexpected value NaN parsing y attribute”。这很清楚。然而,Firebug 中没有行号,也没有显示代码——基本上没有办法追踪这个错误发生的位置。

使用简单的 JS,只需追踪错误代码即可。然而,随着我的 JS 变得越来越复杂,我确实需要能够查看数百条潜在行中的哪一行导致了这种情况。

理想情况下,我希望以与查看 JS 错误或 HTML 错误相同的方式看到此解析错误:

Unexpected value NaN parsing y attribute.
Line 103:    svgElement.setAttribute('x', some_bad_js_variable);

有什么办法可以做到这一点吗?即使知道哪个 SVG 元素受到影响也会有所帮助,除了“某处出现错误”之外的任何信息。谢谢!

Summary:

I want to see more detailed XML/SVG parsing error messages. I want to know where the errors are happening. How can I do this?

Background:

I'm working with some complicated javascript-generated SVG in Firefox. As I'm developing, sometimes while hunting down a big I'll see errors in the Firefox error console (or firebug) "Unexpected value NaN parsing y attribute". This is pretty clear. However, there's no line number, no code shown in Firebug - basically no way to track down where this error occurs.

With simple JS, it's a matter of tracking down the bad code. However, as my JS gets more complicated, I really need to be able to see which of hundreds of potential lines is causing this.

Ideally, I'd like to see this parsing error the same way I see JS errors or HTML errors:

Unexpected value NaN parsing y attribute.
Line 103:    svgElement.setAttribute('x', some_bad_js_variable);

Is there any way to do this? Even knowing which SVG element is being affected would help, anything besides "There was an error somewhere". Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

離人涙 2024-12-12 06:06:27

近三年后,使用 Firefox 29.0.1,我遇到了同样的困难。我最终注释掉了连续的代码块,直到找到有问题的行。

FWIW,就我而言,Firefox 不喜欢我创建了一个具有空白属性的节点:

    <clipPath id="chart_area">
       <rect x="" y="" width="" height=""/>
    </clipPath>

一旦我删除了属性或将它们设置为任何值,问题就消失了。我很惊讶,因为我原以为错误会出现在 Javascript 中。我希望这对其他人有帮助。

Nearly three years later and using Firefox 29.0.1, I have the same difficulty. I ended up commenting out successive blocks of code until I found the offending line.

FWIW, in my case Firefox didn't like the fact that I had created a node with blank attributes:

    <clipPath id="chart_area">
       <rect x="" y="" width="" height=""/>
    </clipPath>

Once I removed the attributes or set them to any value, the problem went away. I was surprised because I'd expected the error to be in the Javascript instead. I hope this helps someone else.

泪冰清 2024-12-12 06:06:27

在 bugzilla 中提出错误并要求将元素标签名称添加到错误消息中: https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=SVG

添加行号会更困难。如果你也想要这个,那么专门为它创建另一个错误,因为你不太可能得到它。

Raise a bug in bugzilla and ask for the element tag name to be added to the error message: https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=SVG

Adding a line number would be more difficult. If want that too then create another bug specifically for it as you're less likely to get it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文