1package entity
2
3import (
4 "fmt"
5 "strings"
6)
7
8type ErrMultipleMatch struct {
9 entityType string
10 Matching []Id
11}
12
13func NewErrMultipleMatch(entityType string, matching []Id) *ErrMultipleMatch {
14 return &ErrMultipleMatch{entityType: entityType, Matching: matching}
15}
16
17func (e ErrMultipleMatch) Error() string {
18 matching := make([]string, len(e.Matching))
19
20 for i, match := range e.Matching {
21 matching[i] = match.String()
22 }
23
24 return fmt.Sprintf("Multiple matching %s found:\n%s",
25 e.entityType,
26 strings.Join(matching, "\n"))
27}
28
29func IsErrMultipleMatch(err error) bool {
30 _, ok := err.(*ErrMultipleMatch)
31 return ok
32}
33
34type ErrInvalidFormat struct {
35 version uint
36 expected uint
37}
38
39func NewErrInvalidFormat(version uint, expected uint) *ErrInvalidFormat {
40 return &ErrInvalidFormat{
41 version: version,
42 expected: expected,
43 }
44}
45
46func NewErrUnknownFormat(expected uint) *ErrInvalidFormat {
47 return &ErrInvalidFormat{
48 version: 0,
49 expected: expected,
50 }
51}
52
53func (e ErrInvalidFormat) Error() string {
54 if e.version == 0 {
55 return fmt.Sprintf("unreadable data, you likely have an outdated repository format, please use https://github.com/MichaelMure/git-bug-migration to upgrade to format version %v", e.expected)
56 }
57 if e.version < e.expected {
58 return fmt.Sprintf("outdated repository format %v, please use https://github.com/MichaelMure/git-bug-migration to upgrade to format version %v", e.version, e.expected)
59 }
60 return fmt.Sprintf("your version of git-bug is too old for this repository (format version %v, expected %v), please upgrade to the latest version", e.version, e.expected)
61}