From 8848a04e0d6e79fc554d7aea81c56775f5091a5c Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Sat, 27 Jul 2019 05:28:03 +0000 Subject: [PATCH] =?UTF-8?q?modelbase:=20=E8=8B=A5GetIModelManager()?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6=E5=90=88=E9=A2=84=E6=9C=9F=E5=88=99panic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 便于定位 --- pkg/cloudcommon/db/modelbase.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/cloudcommon/db/modelbase.go b/pkg/cloudcommon/db/modelbase.go index 4396b60c4a..d0169ef4d9 100644 --- a/pkg/cloudcommon/db/modelbase.go +++ b/pkg/cloudcommon/db/modelbase.go @@ -17,13 +17,13 @@ package db import ( "context" "database/sql" + "fmt" "net/http" + "time" "yunion.io/x/jsonutils" "yunion.io/x/sqlchemy" - "log" - "time" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/object" "yunion.io/x/onecloud/pkg/httperrors" @@ -57,9 +57,13 @@ func NewModelBaseManager(model interface{}, tableName string, keyword string, ke func (manager *SModelBaseManager) GetIModelManager() IModelManager { virt := manager.GetVirtualObject() if virt == nil { - log.Fatalf("%s.GetIModelManager got nil!", manager.keywordPlural) + panic(fmt.Sprintf("Forgot to call SetVirtualObject?")) } - return virt.(IModelManager) + r, ok := virt.(IModelManager) + if !ok { + panic(fmt.Sprintf("Cannot convert virtual object to IModelManager: %#v", virt)) + } + return r } func (manager *SModelBaseManager) SetAlias(alias string, aliasPlural string) {