aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/error.go
blob: c0b9163313109ee34b2aa0503de3cb337d8bc900 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package packfile

import "fmt"

// Error specifies errors returned during packfile parsing.
type Error struct {
	reason, details string
}

// NewError returns a new error.
func NewError(reason string) *Error {
	return &Error{reason: reason}
}

// Error returns a text representation of the error.
func (e *Error) Error() string {
	if e.details == "" {
		return e.reason
	}

	return fmt.Sprintf("%s: %s", e.reason, e.details)
}

// AddDetails adds details to an error, with additional text.
func (e *Error) AddDetails(format string, args ...interface{}) *Error {
	return &Error{
		reason:  e.reason,
		details: fmt.Sprintf(format, args...),
	}
}