Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to errors.Join #22429

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eng/tools/generator/cmd/issue/issueCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package issue
import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"time"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/Azure/azure-sdk-for-go/eng/tools/generator/config/validate"
"github.com/Azure/azure-sdk-for-go/eng/tools/generator/flags"
"github.com/google/go-github/v53/github"
"github.com/hashicorp/go-multierror"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -233,7 +233,7 @@ func (c *commandContext) parseIssues(issues []*github.Issue) ([]request.Request,
}
if isInconsistentTag(issue) {
log.Printf("[ERROR] %s Readme tag is inconsistent with default tag\n", issue.GetHTMLURL())
errResult = multierror.Append(errResult, fmt.Errorf("%s: readme tag is inconsistent with default tag", issue.GetHTMLURL()))
errResult = errors.Join(errResult, fmt.Errorf("%s: readme tag is inconsistent with default tag", issue.GetHTMLURL()))
continue
}

Expand All @@ -243,7 +243,7 @@ func (c *commandContext) parseIssues(issues []*github.Issue) ([]request.Request,
})
if err != nil {
log.Printf("[ERROR] Cannot parse release request %s: %+v", issue.GetHTMLURL(), err)
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
continue
}
if req == nil {
Expand Down
23 changes: 13 additions & 10 deletions eng/tools/generator/cmd/refresh/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package refresh

import (
"errors"
"fmt"
"log"
"path/filepath"
Expand All @@ -20,7 +21,6 @@ import (
sdkutils "github.com/Azure/azure-sdk-for-go/eng/tools/internal/utils"
"github.com/ahmetb/go-linq/v3"
"github.com/go-git/go-git/v5/plumbing"
"github.com/hashicorp/go-multierror"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -226,15 +226,15 @@ func (c *CommandContext) generate(infoMap GenerationMap, additionalOptions []mod
var errResult error
for commit, infoList := range infoMap {
errorsOnCommit := c.generateOnCommit(commit, infoList, additionalOptions)
if len(errorsOnCommit) > 0 {
errResult = multierror.Append(errResult, errorsOnCommit...)
if errorsOnCommit != nil {
errResult = errors.Join(errResult, errorsOnCommit)
}
}

return errResult
}

func (c *CommandContext) generateOnCommit(commit string, infoList []GenerationInfo, additionalOptions []model.Option) []error {
func (c *CommandContext) generateOnCommit(commit string, infoList []GenerationInfo, additionalOptions []model.Option) error {
log.Printf("Regenerate on commit %s starts", commit)
// first we checkout the spec repo to that commit
log.Printf("Checking out to commit %s...", commit)
Expand All @@ -246,15 +246,17 @@ func (c *CommandContext) generateOnCommit(commit string, infoList []GenerationIn
return item.String()
}).ToSlice(&messages)
log.Printf("Error in checking out to '%s' which contains the following packages: \n%s", commit, strings.Join(messages, "\n"))
return []error{fmt.Errorf("cannot checkout to commit '%s': %+v", commit, err)}
return error(fmt.Errorf("cannot checkout to commit '%s': %+v", commit, err))
}
var errors []error
var errResult error
var errCount int
for _, info := range infoList {
log.Printf("start generation task (readme '%s' / tag '%s')", info.Readme, info.Tag)
// build the options from the metadata
options, err := c.buildOptions(info.GenerationMetadata)
if err != nil {
errors = append(errors, err)
errResult = errors.Join(errResult, err)
errCount++
continue
}
options = options.MergeOptions(additionalOptions...)
Expand All @@ -269,13 +271,14 @@ func (c *CommandContext) generateOnCommit(commit string, infoList []GenerationIn
_, err = generateCtx.generate(info)
if err != nil {
log.Printf("fails in generation task (readme %s / tag %s): %+v", info.Readme, info.Tag, err)
errors = append(errors, fmt.Errorf("generate on commit %s failed: %+v", commit, err))
errResult = errors.Join(errResult, fmt.Errorf("generate on commit %s failed: %+v", commit, err))
errCount++
continue
}
log.Printf("done generation of generation task %v (%v)", info, time.Since(start))
}
log.Printf("Regenerate on commit %s finished with %d errors", commit, len(errors))
return errors
log.Printf("Regenerate on commit %s finished with %d errors", commit, errCount)
return errResult
}

func (c *CommandContext) buildOptions(metadata autorest.GenerationMetadata) (model.Options, error) {
Expand Down
4 changes: 2 additions & 2 deletions eng/tools/generator/config/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package config

import (
"encoding/json"
"errors"
"strings"

"github.com/Azure/azure-sdk-for-go/eng/tools/generator/autorest/model"
"github.com/Azure/azure-sdk-for-go/eng/tools/generator/common"
"github.com/hashicorp/go-multierror"
)

type RefreshInfo struct {
Expand Down Expand Up @@ -44,7 +44,7 @@ func parseAdditionalOptions(input []string) ([]model.Option, error) {
for _, f := range input {
o, err := model.NewOption(f)
if err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
continue
}
options = append(options, o)
Expand Down
14 changes: 7 additions & 7 deletions eng/tools/generator/config/validate/localValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package validate

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand All @@ -13,7 +14,6 @@ import (

"github.com/Azure/azure-sdk-for-go/eng/tools/generator/config"
"github.com/ahmetb/go-linq/v3"
"github.com/hashicorp/go-multierror"
)

type localValidator struct {
Expand All @@ -24,24 +24,24 @@ func (v *localValidator) Validate(cfg config.Config) error {
var errResult error
for readme, infoMap := range cfg.Track1Requests {
if err := v.validateReadmeExistence(readme); err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
continue // readme file cannot pass validation, we just skip the validations
}
// get content of the readme
contentOfReadme, err := getReadmeContent(v.specRoot, readme)
if err != nil {
errResult = multierror.Append(errResult, fmt.Errorf("cannot get readme.md content: %+v", err))
errResult = errors.Join(errResult, fmt.Errorf("cannot get readme.md content: %+v", err))
continue
}
// validate the existence of readme.go.md
if err := v.validateReadmeExistence(getReadmeGoFromReadme(readme)); err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
continue // readme.go.md is mandatory
}
// get content of the readme.go.md
contentOfReadmeGo, err := getReadmeContent(v.specRoot, getReadmeGoFromReadme(readme))
if err != nil {
errResult = multierror.Append(errResult, fmt.Errorf("cannot get readme.go.md content: %+v", err))
errResult = errors.Join(errResult, fmt.Errorf("cannot get readme.go.md content: %+v", err))
continue
}
// get the keys from infoMap, which is the tags
Expand All @@ -51,10 +51,10 @@ func (v *localValidator) Validate(cfg config.Config) error {
}).ToSlice(&tags)
// check the tags one by one
if err := validateTagsInReadme(contentOfReadme, readme, tags...); err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
}
if err := validateTagsInReadmeGo(contentOfReadmeGo, readme, tags...); err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
}
}
return errResult
Expand Down
14 changes: 7 additions & 7 deletions eng/tools/generator/config/validate/remoteValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package validate

import (
"context"
"errors"
"fmt"
"strings"

"github.com/Azure/azure-sdk-for-go/eng/tools/generator/cmd/issue/query"
"github.com/Azure/azure-sdk-for-go/eng/tools/generator/config"
"github.com/ahmetb/go-linq/v3"
"github.com/google/go-github/v53/github"
"github.com/hashicorp/go-multierror"
)

type remoteValidator struct {
Expand All @@ -26,25 +26,25 @@ func (v *remoteValidator) Validate(cfg config.Config) error {
// first we validate whether the readme exists
file, err := v.validateReadmeExistence(readme)
if err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
continue // readme file does not exist, we could just skip all of the other steps of validations
}
// get content of the readme
contentOfReadme, err := file.GetContent()
if err != nil {
errResult = multierror.Append(errResult, fmt.Errorf("cannot get readme.md content: %+v", err))
errResult = errors.Join(errResult, fmt.Errorf("cannot get readme.md content: %+v", err))
continue
}
// validate the existence of readme.go.md
fileGo, err := v.validateReadmeExistence(getReadmeGoFromReadme(readme))
if err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
continue // readme.go.md is mandatory
}
// get content of the readme.go.md
contentOfReadmeGo, err := fileGo.GetContent()
if err != nil {
errResult = multierror.Append(errResult, fmt.Errorf("cannot get readme.go.md content: %+v", err))
errResult = errors.Join(errResult, fmt.Errorf("cannot get readme.go.md content: %+v", err))
continue
}
// get the keys from infoMap, which is the tags
Expand All @@ -54,10 +54,10 @@ func (v *remoteValidator) Validate(cfg config.Config) error {
}).ToSlice(&tags)
// check the tags one by one
if err := validateTagsInReadme([]byte(contentOfReadme), readme, tags...); err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
}
if err := validateTagsInReadmeGo([]byte(contentOfReadmeGo), readme, tags...); err != nil {
errResult = multierror.Append(errResult, err)
errResult = errors.Join(errResult, err)
}
}
return errResult
Expand Down
4 changes: 2 additions & 2 deletions eng/tools/generator/config/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package validate

import (
"context"
"errors"
"fmt"
"path/filepath"
"strconv"
Expand All @@ -13,7 +14,6 @@ import (
"github.com/Azure/azure-sdk-for-go/eng/tools/generator/cmd/issue/query"
"github.com/Azure/azure-sdk-for-go/eng/tools/generator/cmd/v2/common"
"github.com/Azure/azure-sdk-for-go/eng/tools/generator/config"
"github.com/hashicorp/go-multierror"
)

type Validator interface {
Expand All @@ -38,7 +38,7 @@ func ParseTrack2(config *config.Config, specRoot string) (armServices map[string
for _, request := range track2Request {
service, err := common.ReadV2ModuleNameToGetNamespace(filepath.Join(specRoot, getReadmeGoFromReadme(readme)))
if err != nil {
errResult = multierror.Append(errResult, fmt.Errorf("cannot get readme.go.md content: %+v", err))
errResult = errors.Join(errResult, fmt.Errorf("cannot get readme.go.md content: %+v", err))
continue
}

Expand Down
18 changes: 8 additions & 10 deletions eng/tools/generator/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
module github.com/Azure/azure-sdk-for-go/eng/tools/generator

go 1.19
go 1.20

require (
github.com/Azure/azure-sdk-for-go/eng/tools/internal v0.0.0-20240117220840-708e50633b35
github.com/Azure/azure-sdk-for-go/eng/tools/internal v0.0.0-20240221072118-775ba01d28c5
github.com/Masterminds/semver v1.5.0
github.com/ahmetb/go-linq/v3 v3.2.0
github.com/go-git/go-git/v5 v5.11.0
github.com/google/go-github/v53 v53.2.0
github.com/hashicorp/go-multierror v1.1.1
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
golang.org/x/oauth2 v0.16.0
golang.org/x/oauth2 v0.17.0
)

require (
Expand All @@ -28,7 +27,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
Expand All @@ -37,11 +35,11 @@ require (
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading