当函数在代码中声明但未调用时,请惊慌

Context: https://github.com/fusspawn/tserver/blob/master/app/controllers/gorp.go

As part of trying to get gorm setup I tried to convert the standard revel/gorp examples.

However. even having the Begin(),Commit(),Rollback() methods defined is enough to cause go to panic.

   TRACE 2015/09/06 17:37:47 harness.go:126: Rebuild                                                                                                  
   INFO  2015/09/06 17:37:47 build.go:172: Cleaning dir tmp                                                                                           
   INFO  2015/09/06 17:37:47 build.go:172: Cleaning dir routes                                                                                        
   INFO  2015/09/06 17:37:47 build.go:172: Cleaning dir tmp                                                                                           
   INFO  2015/09/06 17:37:47 build.go:172: Cleaning dir routes                                                                                        
   TRACE 2015/09/06 17:37:47 build.go:151: Exec: [/usr/bin/git --git-   dir=/home/fusspawn/go/src/github.com/fusspawn/tserver/.git describe --always --   dirty]                                                                                                                                               
   TRACE 2015/09/06 17:37:47 build.go:94: Exec: [/usr/bin/go build -ldflags    -X github.com/fusspawn/tserver/app.APP_VERSION "git-2588ef1" -tags  -o /ho
  me/fusspawn/go/bin/revel.d/github.com/fusspawn/tserver/tserver   github.com/fusspawn/tserver/app/tmp]                                                
   TRACE 2015/09/06 17:39:14 app.go:56: Exec app:   /home/fusspawn/go/bin/revel.d/github.com/fusspawn/tserver/tserver    [/home/fusspawn/go/bin/revel.d/git
   hub.com/fusspawn/tserver/tserver -port=46276 -  importPath=github.com/fusspawn/tserver -runMode=dev]                                                 
   INFO  2015/09/06 17:39:14 revel.go:329: Loaded module static                                                                                       
   INFO  2015/09/06 17:39:14 revel.go:329: Loaded module testrunner                                                                                   
   INFO  2015/09/06 17:39:14 revel.go:206: Initialized Revel v0.12.0 (2015-03-25) for >= go1.3                                                        
   INFO  2015/09/06 17:39:14 main.go:30: Running revel server                                                                                         
   TRACE 2015/09/06 17:39:14 controller.go:402: Registered controller: App                                                                            
   panic: reflect: call of reflect.Value.Type on zero Value                                                                                           

   goroutine 1 [running]:                                                                                                                             
   runtime.panic(0x88cec0, 0xc21011b7a0)                                                                                                              
    /usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6                                                                                              
   reflect.Value.Type(0x0, 0x0, 0x0, 0x0, 0x0)                                                                                                        
    /usr/lib/go/src/pkg/reflect/value.go:1698 +0x79                                                                                            
    github.com/revel/revel.findControllers(0x7f365698bea8, 0x9186e0, 0x0, 0x0, 0x0)                                                                    
    /home/fusspawn/go/src/github.com/revel/revel/controller.go:321 +0x25a                                                                      
    github.com/revel/revel.RegisterController(0x9172a0, 0x0, 0xc2100c4bf0,    0x2, 0x2)                                                                   
     /home/fusspawn/go/src/github.com/revel/revel/controller.go:400 +0x1f3                                                                      
    main.main()                                                                                                                                        
     /home/fusspawn/go/src/github.com/fusspawn/tserver/app/tmp/main.go:150  +0x141b                                                              
     TRACE 2015/09/06 17:39:14 controller.go:402: Registered controller:     GormController                                                                 
     TRACE 2015/09/06 17:39:14 controller.go:402: Registered controller: Static                                                                         
     TRACE 2015/09/06 17:39:14 controller.go:402: Registered controller:  TestRunner             

Commenting out the method definitions will stop the panic. I cant seem to understand how not calling these methods (note the revel.InterceptMethod calls are commented out) can make the panic happen :/

duangai1916
duangai1916 您是否尝试过创建一个最小,完整和可验证的示例?对于潜在的回答者来说,这不仅比查看整个GitHub存储库要容易得多(将来将不再相同,这将使这篇文章变得毫无用处),而且制作mcve的行为可以帮助提问者更好地了解自己的问题。
大约 5 年之前 回复
douduandiao1368
douduandiao1368 抱歉,我花了一点时间与格式战斗
大约 5 年之前 回复

1个回答



根据Revel文档,系统会通过扫描您的源目录,以进行任何匿名嵌入 * Revel.Controller </ code>的操作。 您看到的错误是由于Revel在此控制器扫描初始化过程中进行了动态反射并搞砸了。 所以现在的问题是:为什么扫描控制器时会遇到麻烦?</ p>

您的代码似乎试图在 EventStream ,Revel调试控制器发现代码将尝试将其读取为控制器。 但是,目前的代码通过嵌入 * GormController </ code>而不是 GormController </ code>违反了对框架的期望。 请参见控制器文档的最后一部分。</ p>

我认为,因此,控制器发现逻辑简直令人窒息。 修复 EventStream </ code>结构定义。</ p>

如果这确实为您解决了该问题,则您可能应该向Revel员工发送错误报告,因为错误消息 “回来很糟糕,而且不是本地的,因为它没有提及失败时试图注册为控制器的事物的名称。</ p>
</ div>

展开原文

原文

According to the Revel docs, the system looks for Controllers in debug mode by scanning your source directory for anything that does an anonymous embedding of a *Revel.Controller. The error your're seeing is due to Revel doing dynamic reflection and screwing up during this controller-scanning initialization. So now the question is: why is it having trouble scanning for controllers?

Your code appears to try to extend a controller in EventStream, which the Revel debug controller-discovery code will try to read as a Controller. However, the code as it stands is currently violating expectations of the framework by embedding a *GormController instead of a GormController; see the last part of the Controllers documentation.

I think the controller-discovery logic is simply choking because of this. Fix the EventStream structure definition.

If this does correct the issue for you, you should probably send a bug report to the Revel folks, because the error message you're getting back is pretty bad and non-local, because it doesn't mention the name of the thing it's trying to register as a controller when it fails.

dongqiang5932
dongqiang5932 就是这样 更改EventStream文档以嵌入GormController而不是* GormController停止了恐慌。 当我考虑时,这是完全有意义的。 不太清楚它最初是如何作为* GormController结束的。
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问