使用cytoscape.js处理错误 [英] Handle errors with cytoscape.js

查看:277
本文介绍了使用cytoscape.js处理错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,用户将在其中输入图形数据,然后使用cytoscape.js进行渲染。

I am building a website where users will be inputting graph data, which is then rendered with cytoscape.js.

鉴于这是由用户数据支持的,因此在某些情况下,它们可能会放入无效数据,尤其是缺少目标的边缘。我想捕获此数据并将其呈现给用户,以便他们可以纠正错误。

Given that this is backed by user data, there may be instances where they put in invalid data, specifically edges that have missing targets. I'd like to capture this data and present it to the user so they can fix the errors.

当前,我在日志中收到此错误,但是我无法确定如何捕获数据。

Currently, I get this error in the logs, but I'm unable to figure out how to capture the data.

Can not create edge `TableOfBooks>att` with nonexistant target `att`

我尝试将cytoscape构造函数包装在try ... catch ...块中,但是

I've tried wrapping the cytoscape constructor in a try...catch... block, but it doesn't appear to be catching the error.

try {
  var cy = cytoscape(...);
} catch(err) {
  console.log("ERROR: " + err);
}

我该如何捕捉这些错误?

How can I go about catching these errors?

推荐答案

这只是控制台中的警告。这也不是例外,其类型为 Error 。通常,Cytoscape不会为无效的图JSON引发异常。它包含有效的条目,它会警告您有关无效的条目,然后继续进行,因此开发人员需要检查一些东西。

That's just a warning in the console. It is not an exception, of type Error. In general, Cytoscape does not throw exceptions for invalid graph JSON. It includes valid entries, it warns you about invalid ones, and it continues on so there's something for the dev to inspect.

Cytoscape必须吸引几个小组,其中包括经验不足的小组科学家和经验丰富的程序员。我们发现,如果科学家因小图JSON错误而出现异常,他们会轻易放弃该工具。因此,异常是不可能的。

Cytoscape has to appeal to several groups, including inexperienced scientists and experienced programmers. We've found scientists would give up too easily on the tool if they get an exception for little graph JSON mistakes. So exceptions are a nonstarter.

如果您确实想要引发异常,则可以考虑添加一个可切换标志,用于警告是否在PR中引发异常。从今天开始,所有这些消息都通过 /中的 error() warning() util ,因此您可以在其中添加抛出。

If you really want thrown exceptions, you could look into adding a togglable flag for whether warnings throw exceptions in a PR. As of today, all those messages go through error() or warning() in /util, so you could add throwing there.

Cytoscape不执行用户输入验证。通常,这取决于应用程序,特别是因为它可能包含业务逻辑。

Cytoscape does not do user input validation. That's generally up to the app to do, especially since it could contain business logic.

这篇关于使用cytoscape.js处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆