Skip to content

Commit a2c246e

Browse files
committed
refactor: split out error func
1 parent 39b264a commit a2c246e

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

scripts/contributors/contributors.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,36 +260,37 @@ func validateContributorAvatarURL(avatarURL *string) []error {
260260
return problems
261261
}
262262

263+
func addFilePathToError(filePath string, err error) error {
264+
return fmt.Errorf("%q: %v", filePath, err)
265+
}
266+
263267
func validateContributorYaml(yml contributorProfile) []error {
264268
allProblems := []error{}
265-
addFilePath := func(err error) error {
266-
return fmt.Errorf("%q: %v", yml.filePath, err)
267-
}
268269

269270
if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil {
270-
allProblems = append(allProblems, addFilePath(err))
271+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
271272
}
272273
if err := validateContributorDisplayName(yml.frontmatter.DisplayName); err != nil {
273-
allProblems = append(allProblems, addFilePath(err))
274+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
274275
}
275276
if err := validateContributorLinkedinURL(yml.frontmatter.LinkedinURL); err != nil {
276-
allProblems = append(allProblems, addFilePath(err))
277+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
277278
}
278279
if err := validateContributorWebsite(yml.frontmatter.WebsiteURL); err != nil {
279-
allProblems = append(allProblems, addFilePath(err))
280+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
280281
}
281282
if err := validateContributorStatus(yml.frontmatter.ContributorStatus); err != nil {
282-
allProblems = append(allProblems, addFilePath(err))
283+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
283284
}
284285

285286
for _, err := range validateContributorEmployerGithubUsername(yml.frontmatter.EmployerGithubUsername, yml.frontmatter.GithubUsername) {
286-
allProblems = append(allProblems, addFilePath(err))
287+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
287288
}
288289
for _, err := range validateContributorSupportEmail(yml.frontmatter.SupportEmail) {
289-
allProblems = append(allProblems, addFilePath(err))
290+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
290291
}
291292
for _, err := range validateContributorAvatarURL(yml.frontmatter.AvatarURL) {
292-
allProblems = append(allProblems, addFilePath(err))
293+
allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
293294
}
294295

295296
return allProblems

0 commit comments

Comments
 (0)