Skip to content

Commit 52ca878

Browse files
committed
Replace usage of wrapErrors directly with diag.Diagnostics
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 436b0ea commit 52ca878

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

github/util.go

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

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

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

@@ -254,21 +237,31 @@ func getTeamSlugContext(ctx context.Context, teamIDString string, meta any) (str
254237
var secretNameRegexp = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
255238

256239
func validateSecretNameFunc(v any, path cty.Path) diag.Diagnostics {
257-
errs := make([]error, 0)
240+
var diags diag.Diagnostics
258241
name, ok := v.(string)
259242
if !ok {
260243
return diag.Errorf("expected type of %s to be string", path)
261244
}
262245

263246
if !secretNameRegexp.MatchString(name) {
264-
errs = append(errs, errors.New("secret names can only contain alphanumeric characters or underscores and must not start with a number"))
247+
diags = append(diags, diag.Diagnostic{
248+
Severity: diag.Error,
249+
Detail: "secret names can only contain alphanumeric characters or underscores and must not start with a number",
250+
Summary: "Error",
251+
AttributePath: path,
252+
})
265253
}
266254

267255
if strings.HasPrefix(strings.ToUpper(name), "GITHUB_") {
268-
errs = append(errs, errors.New("secret names must not start with the GITHUB_ prefix"))
256+
diags = append(diags, diag.Diagnostic{
257+
Severity: diag.Error,
258+
Detail: "secret names must not start with the GITHUB_ prefix",
259+
Summary: "Error",
260+
AttributePath: path,
261+
})
269262
}
270263

271-
return wrapErrors(errs)
264+
return diags
272265
}
273266

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

0 commit comments

Comments
 (0)