简体   繁体   English

转到-接口转换[已恢复]-错误

[英]Go - interface conversion [recovered] - error

The test logs show the following error 测试日志显示以下错误

row 0 - got data of type graph.Node but wanted graph.Node
--- FAIL: TestAlls (0.84s)
panic: interface conversion: interface {} is graph.Node, not graph.Node [recovered]
    panic: interface conversion: interface {} is graph.Node, not graph.Node

From the following code 从以下代码

nnn = graph.Node{}
nnn, ok = row[0].(graph.Node)
if !ok {
  log.Printf("row 0 - got data of type %T but wanted graph.Node", nnn)
}
neo4jNode := row[0].(graph.Node)
  • Is it possible that there are two different types with the same name? 是否可能有两个具有相同名称的不同类型? (graph.Node) (graph.Node)
  • In which case, which folders should I clear out? 在这种情况下,应该清除哪些文件夹?
  • What does [recovered] mean? [恢复]是什么意思?

I am using glide install, go clean, go build, go test. 我正在使用滑行安装,清洁,构建,测试。

Is it possible that there are two different types with the same name? 是否可能有两个具有相同名称的不同类型? (graph.Node) (graph.Node)

Yes. 是。 If the code that produces the object (whatever is generating rows ) references a different copy of the same library , the types will not match - for example, if you reference library foo , which has graph vendored, it will be referencing its vendored version, while you are referencing your own version. 如果产生该对象的代码(无论生成的是什么rows )均引用同一库另一个副本 ,则类型将不匹配-例如,如果您引用的库foo (带有graph供应商)将引用其供应商的版本,当您引用自己的版本时。 It's also possible to have two completely different packages (different import paths) both named graph but I'm assuming you've ruled this out. 也可以有两个完全不同的包(不同的导入路径),它们都命名为graph但我假设您已经排除了这一点。

In which case, which folders should I clear out? 在这种情况下,应该清除哪些文件夹?

It's unfortunately not that simple - you need to look carefully at your dependencies. 不幸的是,它并不是那么简单-您需要仔细查看依赖项。 If you're importing a project as a library, and it has its own dependencies vendored, you're going to have a bad time. 如果要将项目导入为库,并且供应了其自己的依赖项,那么您将会遇到麻烦。 That's exactly why it's a bad practice to vendor dependencies in a library (dependencies should only be vendored for binaries). 这就是为什么在库中对供应商的依赖关系是不好的做法的原因(依赖关系应针对二进制文件进行供应)。

What does [recovered] mean? [恢复]是什么意思?

It means a panic was recovered . 这意味着panic已经恢复 This is done by the testing library to return accurate test results in the event of a test causing a panic. 如果测试导致恐慌,则由测试库完成此操作以返回准确的测试结果。

The origin of the problem was multiple glide.yaml (& vendor/) in the repository. 问题的根源是存储库中的多个glide.yaml(&vendor /)。 The solution was to only have a root glide.yaml (& vendor/). 解决方案是仅具有根glide.yaml(&vendor /)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM