mirror of
https://gitee.com/johng/gf.git
synced 2024-12-01 19:57:40 +08:00
fix: marked gcode.CodeInternalPanic for panic (#2860)
This commit is contained in:
parent
35a326e169
commit
ea6a773d60
@ -8,6 +8,8 @@ package gfcmd
|
||||
|
||||
import (
|
||||
_ "github.com/gogf/gf/cmd/gf/v2/internal/packed"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"context"
|
||||
|
||||
@ -38,7 +40,7 @@ func (c *Command) Run(ctx context.Context) {
|
||||
if err, ok := exception.(error); ok {
|
||||
mlog.Print(err.Error())
|
||||
} else {
|
||||
panic(exception)
|
||||
panic(gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -91,7 +91,7 @@ func (c *Core) Transaction(ctx context.Context, f func(ctx context.Context, tx T
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.Newf("%+v", exception)
|
||||
err = gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -277,7 +277,7 @@ func (tx *TXCore) Transaction(ctx context.Context, f func(ctx context.Context, t
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.Newf("%+v", exception)
|
||||
err = gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ var (
|
||||
CodeNotFound = localCode{65, "Not Found", nil} // Resource does not exist.
|
||||
CodeInvalidRequest = localCode{66, "Invalid Request", nil} // Invalid request.
|
||||
CodeNecessaryPackageNotImport = localCode{67, "Necessary Package Not Import", nil} // It needs necessary package import.
|
||||
CodeInternalPanic = localCode{68, "Internal Panic", nil} // An panic occurred internally.
|
||||
CodeBusinessValidationFailed = localCode{300, "Business Validation Failed", nil} // Business validation failed.
|
||||
)
|
||||
|
||||
|
@ -47,12 +47,12 @@ func niceCallFunc(f func()) {
|
||||
panic(v)
|
||||
} else {
|
||||
panic(gerror.WrapCodeSkip(
|
||||
gcode.CodeInternalError, 1, v, "exception recovered",
|
||||
gcode.CodeInternalPanic, 1, v, "exception recovered",
|
||||
))
|
||||
}
|
||||
} else {
|
||||
panic(gerror.NewCodeSkipf(
|
||||
gcode.CodeInternalError, 1, "exception recovered: %+v", exception,
|
||||
gcode.CodeInternalPanic, 1, "exception recovered: %+v", exception,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -67,10 +67,10 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if code := gerror.Code(v); code != gcode.CodeNil {
|
||||
s.handleErrorLog(v, request)
|
||||
} else {
|
||||
s.handleErrorLog(gerror.WrapCodeSkip(gcode.CodeInternalError, 1, v, ""), request)
|
||||
s.handleErrorLog(gerror.WrapCodeSkip(gcode.CodeInternalPanic, 1, v, ""), request)
|
||||
}
|
||||
} else {
|
||||
s.handleErrorLog(gerror.NewCodeSkipf(gcode.CodeInternalError, 1, "%+v", exception), request)
|
||||
s.handleErrorLog(gerror.NewCodeSkipf(gcode.CodeInternalPanic, 1, "%+v", exception), request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func (c *Command) doRun(ctx context.Context, parser *Parser) (value interface{},
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.Newf(`exception recovered: %+v`, exception)
|
||||
err = gerror.NewCodef(gcode.CodeInternalPanic, "exception recovered: %+v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -8,6 +8,8 @@ package gfsnotify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"github.com/gogf/gf/v2/container/glist"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
@ -127,6 +129,9 @@ func (w *Watcher) eventLoop() {
|
||||
case callbackExitEventPanicStr:
|
||||
w.RemoveCallback(callback.Id)
|
||||
default:
|
||||
if e, ok := err.(error); ok {
|
||||
panic(gerror.WrapCode(gcode.CodeInternalPanic, e))
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func (p *Pool) AddWithRecover(ctx context.Context, userFunc Func, recoverFunc Re
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
recoverFunc(ctx, v)
|
||||
} else {
|
||||
recoverFunc(ctx, gerror.Newf(`%+v`, exception))
|
||||
recoverFunc(ctx, gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package gtimer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
@ -51,7 +52,7 @@ func (entry *Entry) Run() {
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
panic(v)
|
||||
} else {
|
||||
panic(gerror.Newf(`exception recovered: %+v`, exception))
|
||||
panic(gerror.NewCodef(gcode.CodeInternalPanic, "exception recovered: %+v", exception))
|
||||
}
|
||||
} else {
|
||||
entry.Close()
|
||||
|
@ -100,7 +100,7 @@ func doMapToMap(params interface{}, pointer interface{}, mapping ...map[string]s
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalError, 1, "%+v", exception)
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalPanic, 1, "%+v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -113,7 +113,7 @@ func doMapToMaps(params interface{}, pointer interface{}, mapping ...map[string]
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalError, 1, "%+v", exception)
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalPanic, 1, "%+v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -100,7 +100,7 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalError, 1, "%+v", exception)
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalPanic, 1, "%+v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -633,7 +633,7 @@ func bindVarToReflectValue(structFieldValue reflect.Value, value interface{}, ma
|
||||
defer func() {
|
||||
if exception := recover(); exception != nil {
|
||||
err = gerror.NewCodef(
|
||||
gcode.CodeInternalError,
|
||||
gcode.CodeInternalPanic,
|
||||
`cannot convert value "%+v" to type "%s":%+v`,
|
||||
value,
|
||||
structFieldValue.Type().String(),
|
||||
|
@ -53,7 +53,7 @@ func doStructs(params interface{}, pointer interface{}, mapping map[string]strin
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalError, 1, "%+v", exception)
|
||||
err = gerror.NewCodeSkipf(gcode.CodeInternalPanic, 1, "%+v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -9,6 +9,7 @@ package gutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
@ -33,7 +34,7 @@ func Try(ctx context.Context, try func(ctx context.Context)) (err error) {
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
err = v
|
||||
} else {
|
||||
err = gerror.Newf(`%+v`, exception)
|
||||
err = gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -49,7 +50,7 @@ func TryCatch(ctx context.Context, try func(ctx context.Context), catch ...func(
|
||||
if v, ok := exception.(error); ok && gerror.HasStack(v) {
|
||||
catch[0](ctx, v)
|
||||
} else {
|
||||
catch[0](ctx, gerror.Newf(`%+v`, exception))
|
||||
catch[0](ctx, gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user