aboutsummaryrefslogtreecommitdiff
path: root/refstore/update_errors.go
blob: f05f37d2547021f0ce3ada5afa11c19dcf333c15 (about) (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package refstore

import "fmt"

// InvalidNameError indicates that one requested reference name is invalid.
type InvalidNameError struct {
	Err error
}

func (err *InvalidNameError) Error() string {
	if err == nil || err.Err == nil {
		return "invalid reference name"
	}

	return fmt.Sprintf("invalid reference name: %v", err.Err)
}

func (err *InvalidNameError) Unwrap() error {
	if err == nil {
		return nil
	}

	return err.Err
}

// InvalidValueError indicates that one requested reference value is invalid.
type InvalidValueError struct {
	Err error
}

func (err *InvalidValueError) Error() string {
	if err == nil || err.Err == nil {
		return "invalid reference value"
	}

	return fmt.Sprintf("invalid reference value: %v", err.Err)
}

func (err *InvalidValueError) Unwrap() error {
	if err == nil {
		return nil
	}

	return err.Err
}

// DuplicateUpdateError indicates that one batch or transaction includes a
// duplicate update target.
type DuplicateUpdateError struct{}

func (err *DuplicateUpdateError) Error() string {
	return "duplicate reference update"
}

// CreateExistsError indicates that one create operation targeted an existing
// reference.
type CreateExistsError struct{}

func (err *CreateExistsError) Error() string {
	return "reference already exists"
}

// IncorrectOldValueError indicates that one operation's expected old value did
// not match the current reference value.
type IncorrectOldValueError struct {
	Actual   string
	Expected string
}

func (err *IncorrectOldValueError) Error() string {
	if err == nil {
		return "incorrect old value provided"
	}

	if err.Actual == "" && err.Expected == "" {
		return "incorrect old value provided"
	}

	return fmt.Sprintf("incorrect old value provided: got %q, expected %q", err.Actual, err.Expected)
}

// ExpectedDetachedError indicates that one operation required a detached
// reference but found a different kind.
type ExpectedDetachedError struct{}

func (err *ExpectedDetachedError) Error() string {
	return "expected detached reference"
}

// ExpectedSymbolicError indicates that one operation required a symbolic
// reference but found a different kind.
type ExpectedSymbolicError struct{}

func (err *ExpectedSymbolicError) Error() string {
	return "expected symbolic reference"
}

// NameConflictError indicates that one reference name conflicts with another
// visible or queued reference name.
type NameConflictError struct {
	Other string
}

func (err *NameConflictError) Error() string {
	if err == nil || err.Other == "" {
		return "reference name conflict"
	}

	return fmt.Sprintf("reference name conflict with %q", err.Other)
}