File: error.go

package info (click to toggle)
golang-github-go-git-go-git 5.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,072 kB
  • sloc: sh: 61; makefile: 29
file content (30 lines) | stat: -rw-r--r-- 645 bytes parent folder | download | duplicates (4)
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...),
	}
}