test-errcode
wangchuxiao 2 years ago
parent 7445f96e66
commit 7fd9a84271

@ -162,7 +162,7 @@ log:
#日志级别 6表示全都打印测试阶段建议设置为6 #日志级别 6表示全都打印测试阶段建议设置为6
remainLogLevel: -1 remainLogLevel: -1
stderr: true stderr: true
withStack: false
elasticSearchSwitch: false elasticSearchSwitch: false
elasticSearchAddr: [ 127.0.0.1:9201 ] elasticSearchAddr: [ 127.0.0.1:9201 ]
elasticSearchUser: "" elasticSearchUser: ""

@ -187,6 +187,7 @@ type config struct {
RemainRotationCount uint `yaml:"remainRotationCount"` RemainRotationCount uint `yaml:"remainRotationCount"`
RemainLogLevel int `yaml:"remainLogLevel"` RemainLogLevel int `yaml:"remainLogLevel"`
Stderr bool `yaml:"stderr"` Stderr bool `yaml:"stderr"`
WithStack bool `yaml:"withStack"`
ElasticSearchSwitch bool `yaml:"elasticSearchSwitch"` ElasticSearchSwitch bool `yaml:"elasticSearchSwitch"`
ElasticSearchAddr []string `yaml:"elasticSearchAddr"` ElasticSearchAddr []string `yaml:"elasticSearchAddr"`
ElasticSearchUser string `yaml:"elasticSearchUser"` ElasticSearchUser string `yaml:"elasticSearchUser"`

@ -7,6 +7,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/tx" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/tx"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
@ -74,6 +75,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse
_, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID)
//有db错误 //有db错误
if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound {
log.ZDebug(ctx, "AddFriendRequest err:%v", err.Error(), "err", err, "unwrap", errors.Unwrap(err))
return err return err
} }
//无错误 则更新 //无错误 则更新

@ -3,6 +3,12 @@ package mw
import ( import (
"context" "context"
"fmt" "fmt"
"math"
"runtime"
"runtime/debug"
"strings"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
@ -12,10 +18,6 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"math"
"runtime"
"runtime/debug"
"strings"
) )
const OperationID = "operationID" const OperationID = "operationID"
@ -87,23 +89,25 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
} }
grpcStatus := status.New(codes.Code(code), codeErr.Msg()) grpcStatus := status.New(codes.Code(code), codeErr.Msg())
var errInfo *errinfo.ErrorInfo var errInfo *errinfo.ErrorInfo
if unwrap != err { if config.Config.Log.WithStack {
sti, ok := err.(interface{ StackTrace() errors.StackTrace }) if unwrap != err {
if ok { sti, ok := err.(interface{ StackTrace() errors.StackTrace })
log.ZWarn(ctx, "rpc server resp", err, "funcName", funcName, "unwrap", unwrap.Error(), "stack", fmt.Sprintf("%+v", err)) if ok {
if fs := sti.StackTrace(); len(fs) > 0 { log.ZWarn(ctx, "rpc server resp", err, "funcName", funcName, "unwrap", unwrap.Error(), "stack", fmt.Sprintf("%+v", err))
pc := uintptr(fs[0]) if fs := sti.StackTrace(); len(fs) > 0 {
fn := runtime.FuncForPC(pc) pc := uintptr(fs[0])
file, line := fn.FileLine(pc) fn := runtime.FuncForPC(pc)
errInfo = &errinfo.ErrorInfo{ file, line := fn.FileLine(pc)
Path: file, errInfo = &errinfo.ErrorInfo{
Line: uint32(line), Path: file,
Name: fn.Name(), Line: uint32(line),
Cause: unwrap.Error(), Name: fn.Name(),
Warp: nil, Cause: unwrap.Error(),
} Warp: nil,
if arr := strings.Split(err.Error(), ": "); len(arr) > 1 { }
errInfo.Warp = arr[:len(arr)-1] if arr := strings.Split(err.Error(), ": "); len(arr) > 1 {
errInfo.Warp = arr[:len(arr)-1]
}
} }
} }
} }

Loading…
Cancel
Save