Debian Codegraph @

plumbing/format/packfile/error.go

raw
1 package packfile
2
3 import "fmt"
4
5 // Error specifies errors returned during packfile parsing.
6 type Error struct {
7 reason, details string
8 }
9
10 // NewError returns a new error.
11 func NewError(reason string) *Error {
12 return &Error{reason: reason}
13 }
14
15 // Error returns a text representation of the error.
16 func (e *Error) Error() string {
17 if e.details == "" {
18 return e.reason
19 }
20
21 return fmt.Sprintf("%s: %s", e.reason, e.details)
22 }
23
24 // AddDetails adds details to an error, with additional text.
25 func (e *Error) AddDetails(format string, args ...interface{}) *Error {
26 return &Error{
27 reason: e.reason,
28 details: fmt.Sprintf(format, args...),
29 }
30 }