/
error.go
132 lines (108 loc) · 3.12 KB
/
error.go
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*This file is part of kuberpult.
Kuberpult is free software: you can redistribute it and/or modify
it under the terms of the Expat(MIT) License as published by
the Free Software Foundation.
Kuberpult is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MIT License for more details.
You should have received a copy of the MIT License
along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
Copyright 2023 freiheit.com*/
package repository
import (
"fmt"
api "github.com/freiheit-com/kuberpult/pkg/api/v1"
)
type CreateReleaseError struct {
response api.CreateReleaseResponse
}
func (e *CreateReleaseError) Error() string {
return e.response.String()
}
func (e *CreateReleaseError) Response() *api.CreateReleaseResponse {
return &e.response
}
func GetCreateReleaseGeneralFailure(err error) *CreateReleaseError {
response := api.CreateReleaseResponseGeneralFailure{
Message: err.Error(),
}
return &CreateReleaseError{
response: api.CreateReleaseResponse{
Response: &api.CreateReleaseResponse_GeneralFailure{
GeneralFailure: &response,
},
},
}
}
func GetCreateReleaseAlreadyExistsSame() *CreateReleaseError {
response := api.CreateReleaseResponseAlreadyExistsSame{}
return &CreateReleaseError{
response: api.CreateReleaseResponse{
Response: &api.CreateReleaseResponse_AlreadyExistsSame{
AlreadyExistsSame: &response,
},
},
}
}
func GetCreateReleaseAlreadyExistsDifferent(firstDifferingField api.DifferingField, diff string) *CreateReleaseError {
response := api.CreateReleaseResponseAlreadyExistsDifferent{
FirstDifferingField: firstDifferingField,
Diff: diff,
}
return &CreateReleaseError{
response: api.CreateReleaseResponse{
Response: &api.CreateReleaseResponse_AlreadyExistsDifferent{
AlreadyExistsDifferent: &response,
},
},
}
}
func GetCreateReleaseTooOld() *CreateReleaseError {
response := api.CreateReleaseResponseTooOld{}
return &CreateReleaseError{
response: api.CreateReleaseResponse{
Response: &api.CreateReleaseResponse_TooOld{
TooOld: &response,
},
},
}
}
func GetCreateReleaseAppNameTooLong(appName string, regExp string, maxLen uint32) *CreateReleaseError {
response := api.CreateReleaseResponseAppNameTooLong{
AppName: appName,
RegExp: regExp,
MaxLen: maxLen,
}
return &CreateReleaseError{
response: api.CreateReleaseResponse{
Response: &api.CreateReleaseResponse_TooLong{
TooLong: &response,
},
},
}
}
type InternalError struct {
inner error
}
func (i *InternalError) String() string {
return fmt.Sprintf("repository internal: %s", i.inner)
}
func (i *InternalError) Unwrap() error {
return i.inner
}
func (i *InternalError) Error() string {
return i.String()
}
var _ error = (*InternalError)(nil)
type LockedError struct {
EnvironmentApplicationLocks map[string]Lock
EnvironmentLocks map[string]Lock
}
func (l *LockedError) String() string {
return fmt.Sprintf("locked")
}
func (l *LockedError) Error() string {
return l.String()
}
var _ error = (*LockedError)(nil)