去除错误提示中的程序文件名中的Workspace目录

This commit is contained in:
刘祥超
2022-04-18 16:31:48 +08:00
parent 9c79152efe
commit d6eec0fa52
3 changed files with 21 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package apps
import ( import (
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/sizes" "github.com/TeaOSLab/EdgeNode/internal/utils/sizes"
"github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/files" "github.com/iwind/TeaGo/files"
@@ -77,7 +78,7 @@ func (this *LogWriter) Write(message string) {
var ok bool var ok bool
_, file, line, ok = runtime.Caller(callDepth) _, file, line, ok = runtime.Caller(callDepth)
if ok { if ok {
file = this.packagePath(file) file = utils.RemoveWorkspace(this.packagePath(file))
} }
} }

View File

@@ -2,6 +2,7 @@ package errors
import ( import (
"errors" "errors"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
@@ -15,7 +16,7 @@ type errorObj struct {
} }
func (this *errorObj) Error() string { func (this *errorObj) Error() string {
s := this.err.Error() + "\n " + this.file s := this.err.Error() + "\n " + utils.RemoveWorkspace(this.file)
if len(this.funcName) > 0 { if len(this.funcName) > 0 {
s += ":" + this.funcName + "()" s += ":" + this.funcName + "()"
} }
@@ -23,7 +24,7 @@ func (this *errorObj) Error() string {
return s return s
} }
// 新错误 // New 新错误
func New(errText string) error { func New(errText string) error {
ptr, file, line, ok := runtime.Caller(1) ptr, file, line, ok := runtime.Caller(1)
funcName := "" funcName := ""
@@ -39,7 +40,7 @@ func New(errText string) error {
} }
} }
// 包装已有错误 // Wrap 包装已有错误
func Wrap(err error) error { func Wrap(err error) error {
if err == nil { if err == nil {
return nil return nil

View File

@@ -0,0 +1,15 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
import "regexp"
var workspaceReg = regexp.MustCompile(`/Edge[A-Z]\w+/`)
func RemoveWorkspace(path string) string {
var indexes = workspaceReg.FindAllStringIndex(path, -1)
if len(indexes) > 0 {
return path[indexes[len(indexes)-1][0]:]
}
return path
}