英文:
Go - interface conversion [recovered] - error
问题
测试日志显示以下错误
第0行 - 获取到了类型为graph.Node的数据,但期望是graph.Node
--- FAIL: TestAlls (0.84s)
panic: 接口转换: 接口{}是graph.Node,而不是graph.Node [已恢复]
panic: 接口转换: 接口{}是graph.Node,而不是graph.Node
从以下代码中
nnn = graph.Node{}
nnn, ok = row[0].(graph.Node)
if !ok {
log.Printf("第0行 - 获取到了类型为%T的数据,但期望是graph.Node", nnn)
}
neo4jNode := row[0].(graph.Node)
- 是否可能存在两个同名的不同类型?(graph.Node)
- 在什么情况下,我应该清除哪些文件夹?
- [已恢复] 是什么意思?
我正在使用glide install、go clean、go build、go test。
英文:
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)
- In which case, which folders should I clear out?
- What does [recovered] mean?
I am using glide install, go clean, go build, go test.
答案1
得分: 1
是否可能存在两种不同类型但名称相同的情况?(graph.Node)
是的。如果生成对象的代码(生成rows
的任何内容)引用了同一库的不同副本,类型将不匹配 - 例如,如果引用了名为foo
的库,其中包含了graph
,它将引用其自己的版本,而你引用的是你自己的版本。还有可能存在两个完全不同的包(不同的导入路径),都被命名为graph
,但我假设你已经排除了这种情况。
在这种情况下,应该清除哪些文件夹?
很不幸,情况并不那么简单 - 你需要仔细查看你的依赖关系。如果你将一个项目作为库导入,并且它有自己的依赖关系,你将会遇到麻烦。这正是为什么在库中使用依赖关系的副本是一个不好的做法(依赖关系应该只在二进制文件中使用)。
[recovered] 是什么意思?
它表示发生了一个panic
,并且已经恢复。这是测试库在测试导致恐慌的情况下返回准确的测试结果所做的操作。
英文:
> Is it possible that there are two different types with the same name? (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. 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.
> 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. This is done by the testing library to return accurate test results in the event of a test causing a panic.
答案2
得分: 0
问题的根源是代码库中存在多个glide.yaml(和vendor/)文件。解决方案是只保留一个根目录下的glide.yaml(和vendor/)文件。
英文:
The origin of the problem was multiple glide.yaml (& vendor/) in the repository. The solution was to only have a root glide.yaml (& vendor/).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论