1package packfile
2
3import "fmt"
4
5// Error specifies errors returned during packfile parsing.
6type Error struct {
7	reason, details string
8}
9
10// NewError returns a new error.
11func NewError(reason string) *Error {
12	return &Error{reason: reason}
13}
14
15// Error returns a text representation of the error.
16func (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.
25func (e *Error) AddDetails(format string, args ...interface{}) *Error {
26	return &Error{
27		reason:  e.reason,
28		details: fmt.Sprintf(format, args...),
29	}
30}
31