mirror of https://github.com/v2ray/v2ray-core
laze init of error messages
parent
1fa83aead5
commit
2d813295e6
|
@ -28,15 +28,23 @@ type hasSeverity interface {
|
||||||
|
|
||||||
// Error is an error object with underlying error.
|
// Error is an error object with underlying error.
|
||||||
type Error struct {
|
type Error struct {
|
||||||
message string
|
format string
|
||||||
|
message []interface{}
|
||||||
inner error
|
inner error
|
||||||
severity Severity
|
severity Severity
|
||||||
path []string
|
path []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *Error) formMessage() string {
|
||||||
|
if len(v.format) == 0 {
|
||||||
|
return serial.Concat(v.message)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(v.format, v.message...)
|
||||||
|
}
|
||||||
|
|
||||||
// Error implements error.Error().
|
// Error implements error.Error().
|
||||||
func (v *Error) Error() string {
|
func (v *Error) Error() string {
|
||||||
msg := v.message
|
msg := v.formMessage()
|
||||||
if v.inner != nil {
|
if v.inner != nil {
|
||||||
msg += " > " + v.inner.Error()
|
msg += " > " + v.inner.Error()
|
||||||
}
|
}
|
||||||
|
@ -103,13 +111,17 @@ func (v *Error) Path(path ...string) *Error {
|
||||||
// New returns a new error object with message formed from given arguments.
|
// New returns a new error object with message formed from given arguments.
|
||||||
func New(msg ...interface{}) *Error {
|
func New(msg ...interface{}) *Error {
|
||||||
return &Error{
|
return &Error{
|
||||||
message: serial.Concat(msg...),
|
message: msg,
|
||||||
severity: SeverityInfo,
|
severity: SeverityInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Format(format string, values ...interface{}) *Error {
|
func Format(format string, values ...interface{}) *Error {
|
||||||
return New(fmt.Sprintf(format, values...))
|
return &Error{
|
||||||
|
format: format,
|
||||||
|
message: values,
|
||||||
|
severity: SeverityInfo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cause returns the root cause of this error.
|
// Cause returns the root cause of this error.
|
||||||
|
|
Loading…
Reference in New Issue