rename error object

pull/1313/head^2
Darien Raymond 6 years ago
parent 122c3e7a5d
commit a3e189c822
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -41,91 +41,91 @@ func (err *Error) pkgPath() string {
} }
// Error implements error.Error(). // Error implements error.Error().
func (v *Error) Error() string { func (err *Error) Error() string {
builder := strings.Builder{} builder := strings.Builder{}
for _, prefix := range v.prefix { for _, prefix := range err.prefix {
builder.WriteByte('[') builder.WriteByte('[')
builder.WriteString(serial.ToString(prefix)) builder.WriteString(serial.ToString(prefix))
builder.WriteString("] ") builder.WriteString("] ")
} }
path := v.pkgPath() path := err.pkgPath()
if len(path) > 0 { if len(path) > 0 {
builder.WriteString(path) builder.WriteString(path)
builder.WriteString(": ") builder.WriteString(": ")
} }
msg := serial.Concat(v.message...) msg := serial.Concat(err.message...)
builder.WriteString(msg) builder.WriteString(msg)
if v.inner != nil { if err.inner != nil {
builder.WriteString(" > ") builder.WriteString(" > ")
builder.WriteString(v.inner.Error()) builder.WriteString(err.inner.Error())
} }
return builder.String() return builder.String()
} }
// Inner implements hasInnerError.Inner() // Inner implements hasInnerError.Inner()
func (v *Error) Inner() error { func (err *Error) Inner() error {
if v.inner == nil { if err.inner == nil {
return nil return nil
} }
return v.inner return err.inner
} }
func (v *Error) Base(err error) *Error { func (err *Error) Base(e error) *Error {
v.inner = err err.inner = e
return v return err
} }
func (v *Error) atSeverity(s log.Severity) *Error { func (err *Error) atSeverity(s log.Severity) *Error {
v.severity = s err.severity = s
return v return err
} }
func (v *Error) Severity() log.Severity { func (err *Error) Severity() log.Severity {
if v.inner == nil { if err.inner == nil {
return v.severity return err.severity
} }
if s, ok := v.inner.(hasSeverity); ok { if s, ok := err.inner.(hasSeverity); ok {
as := s.Severity() as := s.Severity()
if as < v.severity { if as < err.severity {
return as return as
} }
} }
return v.severity return err.severity
} }
// AtDebug sets the severity to debug. // AtDebug sets the severity to debug.
func (v *Error) AtDebug() *Error { func (err *Error) AtDebug() *Error {
return v.atSeverity(log.Severity_Debug) return err.atSeverity(log.Severity_Debug)
} }
// AtInfo sets the severity to info. // AtInfo sets the severity to info.
func (v *Error) AtInfo() *Error { func (err *Error) AtInfo() *Error {
return v.atSeverity(log.Severity_Info) return err.atSeverity(log.Severity_Info)
} }
// AtWarning sets the severity to warning. // AtWarning sets the severity to warning.
func (v *Error) AtWarning() *Error { func (err *Error) AtWarning() *Error {
return v.atSeverity(log.Severity_Warning) return err.atSeverity(log.Severity_Warning)
} }
// AtError sets the severity to error. // AtError sets the severity to error.
func (v *Error) AtError() *Error { func (err *Error) AtError() *Error {
return v.atSeverity(log.Severity_Error) return err.atSeverity(log.Severity_Error)
} }
// String returns the string representation of this error. // String returns the string representation of this error.
func (v *Error) String() string { func (err *Error) String() string {
return v.Error() return err.Error()
} }
// WriteToLog writes current error into log. // WriteToLog writes current error into log.
func (v *Error) WriteToLog(opts ...ExportOption) { func (err *Error) WriteToLog(opts ...ExportOption) {
var holder ExportOptionHolder var holder ExportOptionHolder
for _, opt := range opts { for _, opt := range opts {
@ -133,12 +133,12 @@ func (v *Error) WriteToLog(opts ...ExportOption) {
} }
if holder.SessionID > 0 { if holder.SessionID > 0 {
v.prefix = append(v.prefix, holder.SessionID) err.prefix = append(err.prefix, holder.SessionID)
} }
log.Record(&log.GeneralMessage{ log.Record(&log.GeneralMessage{
Severity: GetSeverity(v), Severity: GetSeverity(err),
Content: v, Content: err,
}) })
} }

Loading…
Cancel
Save