From 5a43fa750d7c83a93b0ba215c05af52a829d697f Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Sat, 5 Dec 2020 04:39:58 +0000 Subject: [PATCH] Adjust trim package name strategy --- common/errors/errors.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common/errors/errors.go b/common/errors/errors.go index 8cae8b80..b7941f1d 100644 --- a/common/errors/errors.go +++ b/common/errors/errors.go @@ -36,12 +36,16 @@ func (err *Error) WithPathObj(obj interface{}) *Error { } func (err *Error) pkgPath() string { - if err.pathObj != nil { - if p := reflect.TypeOf(err.pathObj).PkgPath(); !strings.HasPrefix(p, "main") { - return p[trim:] + if err.pathObj == nil { + return "" + } + path := reflect.TypeOf(err.pathObj).PkgPath() + for i := 0; i < len(path); i++ { + if path[i] == '/' { + return path[trim:] } } - return "" + return path } // Error implements error.Error().