refactor: split out error func

This commit is contained in:
Michael Smith 2025-04-14 13:52:40 +00:00
parent 39b264a7f9
commit a2c246ea06

View File

@ -260,36 +260,37 @@ func validateContributorAvatarURL(avatarURL *string) []error {
return problems return problems
} }
func addFilePathToError(filePath string, err error) error {
return fmt.Errorf("%q: %v", filePath, err)
}
func validateContributorYaml(yml contributorProfile) []error { func validateContributorYaml(yml contributorProfile) []error {
allProblems := []error{} allProblems := []error{}
addFilePath := func(err error) error {
return fmt.Errorf("%q: %v", yml.filePath, err)
}
if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil { if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
if err := validateContributorDisplayName(yml.frontmatter.DisplayName); err != nil { if err := validateContributorDisplayName(yml.frontmatter.DisplayName); err != nil {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
if err := validateContributorLinkedinURL(yml.frontmatter.LinkedinURL); err != nil { if err := validateContributorLinkedinURL(yml.frontmatter.LinkedinURL); err != nil {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
if err := validateContributorWebsite(yml.frontmatter.WebsiteURL); err != nil { if err := validateContributorWebsite(yml.frontmatter.WebsiteURL); err != nil {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
if err := validateContributorStatus(yml.frontmatter.ContributorStatus); err != nil { if err := validateContributorStatus(yml.frontmatter.ContributorStatus); err != nil {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
for _, err := range validateContributorEmployerGithubUsername(yml.frontmatter.EmployerGithubUsername, yml.frontmatter.GithubUsername) { for _, err := range validateContributorEmployerGithubUsername(yml.frontmatter.EmployerGithubUsername, yml.frontmatter.GithubUsername) {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
for _, err := range validateContributorSupportEmail(yml.frontmatter.SupportEmail) { for _, err := range validateContributorSupportEmail(yml.frontmatter.SupportEmail) {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
for _, err := range validateContributorAvatarURL(yml.frontmatter.AvatarURL) { for _, err := range validateContributorAvatarURL(yml.frontmatter.AvatarURL) {
allProblems = append(allProblems, addFilePath(err)) allProblems = append(allProblems, addFilePathToError(yml.filePath, err))
} }
return allProblems return allProblems