Skip to content

Commit

Permalink
Merge pull request #2483 from puerco/revert
Browse files Browse the repository at this point in the history
Revert native go error wrapping
  • Loading branch information
k8s-ci-robot authored Mar 31, 2022
2 parents 40edcce + 9e49060 commit a40bc07
Show file tree
Hide file tree
Showing 73 changed files with 1,019 additions and 1,008 deletions.
4 changes: 2 additions & 2 deletions cmd/ci-reporter/cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package cmd
import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/pkg/errors"
"github.com/shurcooL/githubv4"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -89,7 +89,7 @@ func (r GithubReporter) CollectReportData(cfg *Config) ([]*CIReportRecord, error
// request github projectboard data
githubReportData, err := GetGithubReportData(*cfg, fieldFilter)
if err != nil {
return nil, fmt.Errorf("getting GitHub report data: %w", err)
return nil, errors.Wrap(err, "getting GitHub report data")
}
records := []*CIReportRecord{}

Expand Down
14 changes: 7 additions & 7 deletions cmd/ci-reporter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package cmd

import (
"encoding/json"
"errors"
"fmt"
"os"
"strings"
"time"

"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
"github.com/shurcooL/githubv4"
"github.com/spf13/cobra"
"github.com/tj/go-spin"
Expand Down Expand Up @@ -85,7 +85,7 @@ func RunReport(cfg *Config, reporters *CIReporters) error {

// visualize data
if err := PrintReporterData(cfg, reports); err != nil {
return fmt.Errorf("printing report data: %w", err)
return errors.Wrap(err, "printing report data")
}

return nil
Expand Down Expand Up @@ -195,7 +195,7 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
// open output file
fileOut, err := os.OpenFile(cfg.Filepath, os.O_WRONLY|os.O_CREATE, 0o666)
if err != nil {
return fmt.Errorf("could not open or create a file at %s to write the ci signal report to: %w", cfg.Filepath, err)
return errors.Wrapf(err, "could not open or create a file at %s to write the ci signal report to", cfg.Filepath)
}
out = fileOut
} else {
Expand All @@ -212,11 +212,11 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
// print report in json format
d, err := reports.Marshal()
if err != nil {
return fmt.Errorf("could not marshal report data: %w", err)
return errors.Wrap(err, "could not marshal report data")
}
_, err = out.WriteString(string(d))
if err != nil {
return fmt.Errorf("could not write to output stream: %w", err)
return errors.Wrap(err, "could not write to output stream")
}
return nil
}
Expand All @@ -226,7 +226,7 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
// write header
_, err := out.WriteString(fmt.Sprintf("\n%s REPORT\n\n", strings.ToUpper(string(r.Info.Name))))
if err != nil {
return fmt.Errorf("could not write to output stream: %w", err)
return errors.Wrap(err, "could not write to output stream")
}

table := tablewriter.NewWriter(out)
Expand Down Expand Up @@ -266,7 +266,7 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
categoryCounts += fmt.Sprintf("%s:%d ", category, categoryCount)
}
if _, err := out.WriteString(fmt.Sprintf("\nSUMMARY - Total:%d %s\n", len(data), categoryCounts)); err != nil {
return fmt.Errorf("could not write to output stream: %w", err)
return errors.Wrap(err, "could not write to output stream")
}
}
return nil
Expand Down
13 changes: 7 additions & 6 deletions cmd/krel/cmd/announce_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"
"text/template"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -176,7 +177,7 @@ func runBuildBranchAnnounce(opts *buildBranchAnnounceOptions, buildOpts *buildAn
if err := t.Execute(&annoucement, struct {
Branch string
}{opts.branch}); err != nil {
return fmt.Errorf("generating the announcement html file: %w", err)
return errors.Wrap(err, "generating the announcement html file")
}

announcementSubject := fmt.Sprintf("Kubernetes %s branch has been created", opts.branch)
Expand All @@ -186,7 +187,7 @@ func runBuildBranchAnnounce(opts *buildBranchAnnounceOptions, buildOpts *buildAn
// runBuildReleaseAnnounce build the announcement file when creating a new Kubernetes release
func runBuildReleaseAnnounce(opts *buildReleaseAnnounceOptions, buildOpts *buildAnnounceOptions, announceOpts *announceOptions) error {
if err := announceOpts.Validate(); err != nil {
return fmt.Errorf("validating annoucement send options: %w", err)
return errors.Wrap(err, "validating annoucement send options")
}

logrus.Info("Building release announcement for new release")
Expand Down Expand Up @@ -222,7 +223,7 @@ func runBuildReleaseAnnounce(opts *buildReleaseAnnounceOptions, buildOpts *build
filepath.Base(opts.changelogFilePath),
string(changelogHTML),
}); err != nil {
return fmt.Errorf("generating the announcement html file: %w", err)
return errors.Wrap(err, "generating the announcement html file")
}

announcementSubject := fmt.Sprintf("Kubernetes %s is live!", announceOpts.tag)
Expand All @@ -237,14 +238,14 @@ func (opts *buildAnnounceOptions) saveAnnouncement(announcementSubject string, a
logrus.Infof("Writing HTML file to %s", absOutputPath)
err := os.WriteFile(absOutputPath, annoucement.Bytes(), os.FileMode(0o644))
if err != nil {
return fmt.Errorf("saving announcement.html: %w", err)
return errors.Wrap(err, "saving announcement.html")
}

absOutputPath = filepath.Join(opts.workDir, "announcement-subject.txt")
logrus.Infof("Writing announcement subject to %s", absOutputPath)
err = os.WriteFile(absOutputPath, []byte(announcementSubject), os.FileMode(0o644))
if err != nil {
return fmt.Errorf("saving announcement-subject.txt: %w", err)
return errors.Wrap(err, "saving announcement-subject.txt")
}

logrus.Info("Kubernetes Announcement created.")
Expand All @@ -256,7 +257,7 @@ func getGoVersion() (string, error) {
"go", "version").
RunSilentSuccessOutput()
if err != nil {
return "", fmt.Errorf("get go version: %w", err)
return "", errors.Wrap(err, "get go version")
}

versionRegex := regexp.MustCompile(semVerRegex)
Expand Down
18 changes: 9 additions & 9 deletions cmd/krel/cmd/announce_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package cmd

import (
"errors"
"fmt"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -110,7 +110,7 @@ func init() {

func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, rootOpts *rootOptions) error {
if err := announceRootOpts.Validate(); err != nil {
return fmt.Errorf("validating annoucement send options: %w", err)
return errors.Wrap(err, "validating annoucement send options")
}
logrus.Info("Retrieving release announcement from Google Cloud Bucket")

Expand All @@ -123,8 +123,8 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r

content, err := http.GetURLResponse(u, false)
if err != nil {
return fmt.Errorf(
"unable to retrieve release announcement form url: %s: %w", u, err,
return errors.Wrapf(err,
"unable to retrieve release announcement form url: %s", u,
)
}

Expand All @@ -135,7 +135,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r
}

if opts.sendgridAPIKey == "" {
return fmt.Errorf(
return errors.Errorf(
"$%s is not set", sendgridAPIKeyEnvKey,
)
}
Expand All @@ -145,12 +145,12 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r

if opts.name != "" && opts.email != "" {
if err := m.SetSender(opts.name, opts.email); err != nil {
return fmt.Errorf("unable to set mail sender: %w", err)
return errors.Wrap(err, "unable to set mail sender")
}
} else {
logrus.Info("Retrieving default sender from sendgrid API")
if err := m.SetDefaultSender(); err != nil {
return fmt.Errorf("setting default sender: %w", err)
return errors.Wrap(err, "setting default sender")
}
}

Expand All @@ -164,7 +164,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r
logrus.Infof("Using Google Groups as announcement target: %v", groups)

if err := m.SetGoogleGroupRecipients(groups...); err != nil {
return fmt.Errorf("unable to set mail recipients: %w", err)
return errors.Wrap(err, "unable to set mail recipients")
}

logrus.Info("Sending mail")
Expand All @@ -181,7 +181,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r

if yes {
if err := m.Send(content, subject); err != nil {
return fmt.Errorf("unable to send mail: %w", err)
return errors.Wrap(err, "unable to send mail")
}
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/krel/cmd/ci_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"k8s.io/release/pkg/build"
Expand Down Expand Up @@ -49,7 +50,7 @@ var ciBuildCmd = &cobra.Command{
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := runCIBuild(ciBuildOpts); err != nil {
return fmt.Errorf("failed to run: %w", err)
return errors.Wrap(err, "failed to run")
}

return nil
Expand Down
21 changes: 10 additions & 11 deletions cmd/krel/cmd/cve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ package cmd

import (
"bytes"
"errors"
"fmt"
"os"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -88,7 +87,7 @@ var argFunc = func(cmd *cobra.Command, args []string) error {
}
cveOpts.CVE = strings.ToUpper(args[0])
if err := cve.NewClient().CheckID(cveOpts.CVE); err != nil {
return fmt.Errorf("invalid CVE ID. Format must match %s", cve.CVEIDRegExp)
return errors.Errorf("invalid CVE ID. Format must match %s", cve.CVEIDRegExp)
}
return nil
}
Expand All @@ -114,20 +113,20 @@ func writeNewCVE(opts *cveOptions) (err error) {

file, err := client.CreateEmptyMap(opts.CVE)
if err != nil {
return fmt.Errorf("creating new cve data map: %w", err)
return errors.Wrap(err, "creating new cve data map")
}

oldFile, err := os.ReadFile(file.Name())
if err != nil {
return fmt.Errorf("reading local copy of CVE entry: %w", err)
return errors.Wrap(err, "reading local copy of CVE entry")
}

kubeEditor := editor.NewDefaultEditor([]string{"KUBE_EDITOR", "EDITOR"})
changes, tempFilePath, err := kubeEditor.LaunchTempFile(
"cve-datamap-", ".yaml", bytes.NewReader(oldFile),
)
if err != nil {
return fmt.Errorf("launching editor: %w", err)
return errors.Wrap(err, "launching editor")
}

if bytes.Equal(changes, oldFile) || len(changes) == 0 {
Expand All @@ -146,7 +145,7 @@ func writeCVEFiles(opts *cveOptions) error {
client := cve.NewClient()
for _, mapFile := range opts.mapFiles {
if err := client.Write(opts.CVE, mapFile); err != nil {
return fmt.Errorf("writing map file %s: %w", mapFile, err)
return errors.Wrapf(err, "writing map file %s", mapFile)
}
}
return nil
Expand All @@ -171,7 +170,7 @@ func editCVE(opts *cveOptions) (err error) {
// or we should first pull the data from the bucket
exists, err := client.EntryExists(opts.CVE)
if err != nil {
return fmt.Errorf("checking if cve entry exists: %w", err)
return errors.Wrap(err, "checking if cve entry exists")
}

if exists {
Expand All @@ -187,19 +186,19 @@ func editExistingCVE(opts *cveOptions) (err error) {
client := cve.NewClient()
file, err := client.CopyToTemp(opts.CVE)
if err != nil {
return fmt.Errorf("copying CVE entry for edting: %w", err)
return errors.Wrap(err, "copying CVE entry for edting")
}
oldFile, err := os.ReadFile(file.Name())
if err != nil {
return fmt.Errorf("reading local copy of CVE entry: %w", err)
return errors.Wrap(err, "reading local copy of CVE entry")
}

kubeEditor := editor.NewDefaultEditor([]string{"KUBE_EDITOR", "EDITOR"})
changes, tempFilePath, err := kubeEditor.LaunchTempFile(
"cve-datamap-", ".yaml", bytes.NewReader(oldFile),
)
if err != nil {
return fmt.Errorf("launching editor: %w", err)
return errors.Wrap(err, "launching editor")
}

if bytes.Equal(changes, oldFile) || len(changes) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/krel/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"k8s.io/release/pkg/build"
Expand Down Expand Up @@ -50,7 +51,7 @@ var pushBuildCmd = &cobra.Command{
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := runPushBuild(pushBuildOpts); err != nil {
return fmt.Errorf("failed to run: %w", err)
return errors.Wrap(err, "failed to run")
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/krel/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -137,7 +138,7 @@ func runRelease(options *anago.ReleaseOptions) error {
// Perform a local check of the specified options
// before launching a Cloud Build job:
if err := options.Validate(&anago.State{}); err != nil {
return fmt.Errorf("prechecking release options: %w", err)
return errors.Wrap(err, "prechecking release options")
}
return rel.Submit(stream)
}
Expand Down
Loading

0 comments on commit a40bc07

Please sign in to comment.