mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
improve error handling for package gconv
This commit is contained in:
@ -21,6 +21,14 @@ import (
|
||||
"github.com/gogf/gf/encoding/gbinary"
|
||||
)
|
||||
|
||||
type (
|
||||
// errorStack is the interface for Stack feature.
|
||||
errorStack interface {
|
||||
Error() string
|
||||
Stack() string
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
// Empty strings.
|
||||
emptyStringMap = map[string]struct{}{
|
||||
|
||||
@ -444,8 +444,12 @@ func doMapToMap(params interface{}, pointer interface{}, mapping ...map[string]s
|
||||
}
|
||||
defer func() {
|
||||
// Catch the panic, especially the reflect operation panics.
|
||||
if e := recover(); e != nil {
|
||||
err = gerror.NewSkipf(1, "%v", e)
|
||||
if exception := recover(); exception != nil {
|
||||
if e, ok := exception.(errorStack); ok {
|
||||
err = e
|
||||
} else {
|
||||
err = gerror.NewSkipf(1, "%v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
var (
|
||||
@ -544,8 +548,12 @@ func doMapToMaps(params interface{}, pointer interface{}, mapping ...map[string]
|
||||
}
|
||||
defer func() {
|
||||
// Catch the panic, especially the reflect operation panics.
|
||||
if e := recover(); e != nil {
|
||||
err = gerror.NewSkipf(1, "%v", e)
|
||||
if exception := recover(); exception != nil {
|
||||
if e, ok := exception.(errorStack); ok {
|
||||
err = e
|
||||
} else {
|
||||
err = gerror.NewSkipf(1, "%v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
var (
|
||||
|
||||
@ -53,8 +53,12 @@ func doStruct(params interface{}, pointer interface{}, mapping ...map[string]str
|
||||
|
||||
defer func() {
|
||||
// Catch the panic, especially the reflect operation panics.
|
||||
if e := recover(); e != nil {
|
||||
err = gerror.NewSkipf(1, "%v", e)
|
||||
if exception := recover(); exception != nil {
|
||||
if e, ok := exception.(errorStack); ok {
|
||||
err = e
|
||||
} else {
|
||||
err = gerror.NewSkipf(1, "%v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@ -45,8 +45,12 @@ func doStructs(params interface{}, pointer interface{}, mapping ...map[string]st
|
||||
|
||||
defer func() {
|
||||
// Catch the panic, especially the reflect operation panics.
|
||||
if e := recover(); e != nil {
|
||||
err = gerror.NewSkipf(1, "%v", e)
|
||||
if exception := recover(); exception != nil {
|
||||
if e, ok := exception.(errorStack); ok {
|
||||
err = e
|
||||
} else {
|
||||
err = gerror.NewSkipf(1, "%v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
// If given <params> is JSON, it then uses json.Unmarshal doing the converting.
|
||||
|
||||
Reference in New Issue
Block a user