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

chore: use errors.New to replace fmt.Errorf with no parameters #70800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions src/go/doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package doc

import (
"errors"
"fmt"
"go/ast"
"go/doc/comment"
Expand Down Expand Up @@ -208,7 +209,7 @@ func (p *Package) collectFuncs(funcs []*Func) {
func NewFromFiles(fset *token.FileSet, files []*ast.File, importPath string, opts ...any) (*Package, error) {
// Check for invalid API usage.
if fset == nil {
panic(fmt.Errorf("doc.NewFromFiles: no token.FileSet provided (fset == nil)"))
panic(errors.New("doc.NewFromFiles: no token.FileSet provided (fset == nil)"))
}
var mode Mode
switch len(opts) { // There can only be 0 or 1 options, so a simple switch works for now.
Expand All @@ -217,11 +218,11 @@ func NewFromFiles(fset *token.FileSet, files []*ast.File, importPath string, opt
case 1:
m, ok := opts[0].(Mode)
if !ok {
panic(fmt.Errorf("doc.NewFromFiles: option argument type must be doc.Mode"))
panic(errors.New("doc.NewFromFiles: option argument type must be doc.Mode"))
}
mode = m
default:
panic(fmt.Errorf("doc.NewFromFiles: there must not be more than 1 option argument"))
panic(errors.New("doc.NewFromFiles: there must not be more than 1 option argument"))
}

// Collect .go and _test.go files.
Expand Down
2 changes: 1 addition & 1 deletion src/go/internal/gccgoimporter/ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func aixBigArExportData(archive io.ReadSeeker) (io.ReadSeeker, error) {
}
}

return nil, fmt.Errorf(".go_export not found in this archive")
return nil, errors.New(".go_export not found in this archive")
}

// readerAtFromSeeker turns an io.ReadSeeker into an io.ReaderAt.
Expand Down
5 changes: 3 additions & 2 deletions src/go/types/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package types

import (
"cmp"
"errors"
"fmt"
"go/ast"
"go/constant"
Expand Down Expand Up @@ -89,7 +90,7 @@ func validatedImportPath(path string) (string, error) {
return "", err
}
if s == "" {
return "", fmt.Errorf("empty string")
return "", errors.New("empty string")
}
const illegalChars = `!"#$%&'()*,:;<=>?[\]^{|}` + "`\uFFFD"
for _, r := range s {
Expand Down Expand Up @@ -157,7 +158,7 @@ func (check *Checker) importPackage(at positioner, path, dir string) *Package {
// ordinary import
var err error
if importer := check.conf.Importer; importer == nil {
err = fmt.Errorf("Config.Importer not installed")
err = errors.New("Config.Importer not installed")
} else if importerFrom, ok := importer.(ImporterFrom); ok {
imp, err = importerFrom.ImportFrom(path, dir, 0)
if imp == nil && err == nil {
Expand Down
2 changes: 1 addition & 1 deletion src/io/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestReadAtLeastWithDataAndEOF(t *testing.T) {

func TestReadAtLeastWithDataAndError(t *testing.T) {
var rb dataAndErrorBuffer
rb.err = fmt.Errorf("fake error")
rb.err = errors.New("fake error")
testReadAtLeast(t, &rb)
}

Expand Down