1 Star 0 Fork 0

api-go/revel-cmd

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
build_error.go 971 Bytes
Copy Edit Raw Blame History
NotZippy authored 2018-09-27 21:08 . Enhancements to Revel command
package utils
import (
"fmt"
"github.com/revel/cmd/logger"
)
type (
BuildError struct {
Stack interface{}
Message string
Args []interface{}
}
)
// Returns a new builed error
func NewBuildError(message string, args ...interface{}) (b *BuildError) {
Logger.Info(message, args...)
b = &BuildError{}
b.Message = message
b.Args = args
b.Stack = logger.NewCallStack()
Logger.Info("Stack", "stack", b.Stack)
return b
}
// Returns a new BuildError if err is not nil
func NewBuildIfError(err error, message string, args ...interface{}) (b error) {
if err != nil {
if berr, ok := err.(*BuildError); ok {
// This is already a build error so just append the args
berr.Args = append(berr.Args, args...)
return berr
} else {
args = append(args, "error", err.Error())
b = NewBuildError(message, args...)
}
}
return
}
// BuildError implements Error() string
func (b *BuildError) Error() string {
return fmt.Sprint(b.Message, b.Args)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/netscript/revel-cmd.git
git@gitee.com:netscript/revel-cmd.git
netscript
revel-cmd
revel-cmd
v0.20.1

Search