Skip to content

Commit

Permalink
fix: 修复 super.RegError 和 RegErrorRef 空指针问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Sep 9, 2023
1 parent 5103103 commit 82973dd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions utils/super/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
)

var errorManagerInstance *errorManager
var errorManagerMutex sync.Mutex

// RegError 通过错误码注册错误,返回错误的引用
func RegError(code int, message string) error {
if code == 0 {
return errors.New("error code can not be 0")
}
errorManagerInstance.mutex.Lock()
defer errorManagerInstance.mutex.Unlock()
errorManagerMutex.Lock()
defer errorManagerMutex.Unlock()
if errorManagerInstance == nil {
errorManagerInstance = new(errorManager).init()
}
Expand All @@ -28,8 +29,8 @@ func RegErrorRef(code int, message string, ref error) error {
if code == 0 {
return errors.New("error code can not be 0")
}
errorManagerInstance.mutex.Lock()
defer errorManagerInstance.mutex.Unlock()
errorManagerMutex.Lock()
defer errorManagerMutex.Unlock()
if errorManagerInstance == nil {
errorManagerInstance = new(errorManager).init()
}
Expand All @@ -45,8 +46,8 @@ func GetError(err error) (int, error) {
if unw == nil {
unw = err
}
errorManagerInstance.mutex.Lock()
defer errorManagerInstance.mutex.Unlock()
errorManagerMutex.Lock()
defer errorManagerMutex.Unlock()
if ref, exist := errorManagerInstance.errorMapperRef[unw]; exist {
//err = fmt.Errorf("%w : %s", ref, err.Error())
err = ref
Expand Down

0 comments on commit 82973dd

Please sign in to comment.