Skip to content

Commit a526e49

Browse files
committed
Replace usage of wrapErrors directly with diag.Diagnostics
Signed-off-by: Timo Sand <[email protected]>
1 parent de461d7 commit a526e49

1 file changed

Lines changed: 16 additions & 23 deletions

File tree

github/util.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,15 @@ func caseInsensitive() schema.SchemaDiffSuppressFunc {
110110
}
111111
}
112112

113-
// wrapErrors is provided to easily turn errors into diag.Diagnostics
114-
// until we go through the provider and replace error usage.
115-
func wrapErrors(errs []error) diag.Diagnostics {
116-
var diags diag.Diagnostics
117-
118-
for _, err := range errs {
119-
diags = append(diags, diag.Diagnostic{
120-
Severity: diag.Error,
121-
Summary: "Error",
122-
Detail: err.Error(),
123-
})
124-
}
125-
126-
return diags
127-
}
128-
129113
func validateValueFunc(values []string) schema.SchemaValidateDiagFunc {
130114
return func(v any, k cty.Path) diag.Diagnostics {
131-
errs := make([]error, 0)
132115
value := v.(string)
133116
valid := slices.Contains(values, value)
134117

135118
if !valid {
136-
errs = append(errs, fmt.Errorf("%s is an invalid value for argument %s", value, k))
119+
return diag.Errorf("%s is an invalid value for argument %s", value, k)
137120
}
138-
return wrapErrors(errs)
121+
return nil
139122
}
140123
}
141124

@@ -197,21 +180,31 @@ func (e *unconvertibleIdError) Error() string {
197180
var secretNameRegexp = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
198181

199182
func validateSecretNameFunc(v any, path cty.Path) diag.Diagnostics {
200-
errs := make([]error, 0)
183+
var diags diag.Diagnostics
201184
name, ok := v.(string)
202185
if !ok {
203186
return diag.Errorf("expected type of %s to be string", path)
204187
}
205188

206189
if !secretNameRegexp.MatchString(name) {
207-
errs = append(errs, errors.New("secret names can only contain alphanumeric characters or underscores and must not start with a number"))
190+
diags = append(diags, diag.Diagnostic{
191+
Severity: diag.Error,
192+
Detail: "secret names can only contain alphanumeric characters or underscores and must not start with a number",
193+
Summary: "Error",
194+
AttributePath: path,
195+
})
208196
}
209197

210198
if strings.HasPrefix(strings.ToUpper(name), "GITHUB_") {
211-
errs = append(errs, errors.New("secret names must not start with the GITHUB_ prefix"))
199+
diags = append(diags, diag.Diagnostic{
200+
Severity: diag.Error,
201+
Detail: "secret names must not start with the GITHUB_ prefix",
202+
Summary: "Error",
203+
AttributePath: path,
204+
})
212205
}
213206

214-
return wrapErrors(errs)
207+
return diags
215208
}
216209

217210
// deleteResourceOn404AndSwallow304OtherwiseReturnError will log and delete resource if error is 404 which indicates resource (or any of its ancestors)

0 commit comments

Comments
 (0)