src/pkg/[a-m]*: gofix -r error -force=error
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5322051
diff --git a/src/pkg/exec/exec.go b/src/pkg/exec/exec.go
index 3b818c2..ebdfd54 100644
--- a/src/pkg/exec/exec.go
+++ b/src/pkg/exec/exec.go
@@ -9,6 +9,7 @@
import (
"bytes"
+ "errors"
"io"
"os"
"strconv"
@@ -18,12 +19,12 @@
// Error records the name of a binary that failed to be be executed
// and the reason it failed.
type Error struct {
- Name string
- Error os.Error
+ Name string
+ Err error
}
-func (e *Error) String() string {
- return "exec: " + strconv.Quote(e.Name) + ": " + e.Error.String()
+func (e *Error) Error() string {
+ return "exec: " + strconv.Quote(e.Name) + ": " + e.Err.Error()
}
// Cmd represents an external command being prepared or run.
@@ -75,13 +76,13 @@
// Process is the underlying process, once started.
Process *os.Process
- err os.Error // last error (from LookPath, stdin, stdout, stderr)
- finished bool // when Wait was called
+ err error // last error (from LookPath, stdin, stdout, stderr)
+ finished bool // when Wait was called
childFiles []*os.File
closeAfterStart []io.Closer
closeAfterWait []io.Closer
- goroutine []func() os.Error
- errch chan os.Error // one send per goroutine
+ goroutine []func() error
+ errch chan error // one send per goroutine
}
// Command returns the Cmd struct to execute the named program with
@@ -132,7 +133,7 @@
return []string{c.Path}
}
-func (c *Cmd) stdin() (f *os.File, err os.Error) {
+func (c *Cmd) stdin() (f *os.File, err error) {
if c.Stdin == nil {
f, err = os.Open(os.DevNull)
c.closeAfterStart = append(c.closeAfterStart, f)
@@ -150,7 +151,7 @@
c.closeAfterStart = append(c.closeAfterStart, pr)
c.closeAfterWait = append(c.closeAfterWait, pw)
- c.goroutine = append(c.goroutine, func() os.Error {
+ c.goroutine = append(c.goroutine, func() error {
_, err := io.Copy(pw, c.Stdin)
if err1 := pw.Close(); err == nil {
err = err1
@@ -160,18 +161,18 @@
return pr, nil
}
-func (c *Cmd) stdout() (f *os.File, err os.Error) {
+func (c *Cmd) stdout() (f *os.File, err error) {
return c.writerDescriptor(c.Stdout)
}
-func (c *Cmd) stderr() (f *os.File, err os.Error) {
+func (c *Cmd) stderr() (f *os.File, err error) {
if c.Stderr != nil && interfaceEqual(c.Stderr, c.Stdout) {
return c.childFiles[1], nil
}
return c.writerDescriptor(c.Stderr)
}
-func (c *Cmd) writerDescriptor(w io.Writer) (f *os.File, err os.Error) {
+func (c *Cmd) writerDescriptor(w io.Writer) (f *os.File, err error) {
if w == nil {
f, err = os.OpenFile(os.DevNull, os.O_WRONLY, 0)
c.closeAfterStart = append(c.closeAfterStart, f)
@@ -189,7 +190,7 @@
c.closeAfterStart = append(c.closeAfterStart, pw)
c.closeAfterWait = append(c.closeAfterWait, pr)
- c.goroutine = append(c.goroutine, func() os.Error {
+ c.goroutine = append(c.goroutine, func() error {
_, err := io.Copy(w, pr)
return err
})
@@ -205,7 +206,7 @@
// If the command fails to run or doesn't complete successfully, the
// error is of type *ExitError. Other error types may be
// returned for I/O problems.
-func (c *Cmd) Run() os.Error {
+func (c *Cmd) Run() error {
if err := c.Start(); err != nil {
return err
}
@@ -213,15 +214,15 @@
}
// Start starts the specified command but does not wait for it to complete.
-func (c *Cmd) Start() os.Error {
+func (c *Cmd) Start() error {
if c.err != nil {
return c.err
}
if c.Process != nil {
- return os.NewError("exec: already started")
+ return errors.New("exec: already started")
}
- type F func(*Cmd) (*os.File, os.Error)
+ type F func(*Cmd) (*os.File, error)
for _, setupFd := range []F{(*Cmd).stdin, (*Cmd).stdout, (*Cmd).stderr} {
fd, err := setupFd(c)
if err != nil {
@@ -231,7 +232,7 @@
}
c.childFiles = append(c.childFiles, c.ExtraFiles...)
- var err os.Error
+ var err error
c.Process, err = os.StartProcess(c.Path, c.argv(), &os.ProcAttr{
Dir: c.Dir,
Files: c.childFiles,
@@ -246,9 +247,9 @@
fd.Close()
}
- c.errch = make(chan os.Error, len(c.goroutine))
+ c.errch = make(chan error, len(c.goroutine))
for _, fn := range c.goroutine {
- go func(fn func() os.Error) {
+ go func(fn func() error) {
c.errch <- fn()
}(fn)
}
@@ -261,7 +262,7 @@
*os.Waitmsg
}
-func (e *ExitError) String() string {
+func (e *ExitError) Error() string {
return e.Waitmsg.String()
}
@@ -275,17 +276,17 @@
// If the command fails to run or doesn't complete successfully, the
// error is of type *ExitError. Other error types may be
// returned for I/O problems.
-func (c *Cmd) Wait() os.Error {
+func (c *Cmd) Wait() error {
if c.Process == nil {
- return os.NewError("exec: not started")
+ return errors.New("exec: not started")
}
if c.finished {
- return os.NewError("exec: Wait was already called")
+ return errors.New("exec: Wait was already called")
}
c.finished = true
msg, err := c.Process.Wait(0)
- var copyError os.Error
+ var copyError error
for _ = range c.goroutine {
if err := <-c.errch; err != nil && copyError == nil {
copyError = err
@@ -306,9 +307,9 @@
}
// Output runs the command and returns its standard output.
-func (c *Cmd) Output() ([]byte, os.Error) {
+func (c *Cmd) Output() ([]byte, error) {
if c.Stdout != nil {
- return nil, os.NewError("exec: Stdout already set")
+ return nil, errors.New("exec: Stdout already set")
}
var b bytes.Buffer
c.Stdout = &b
@@ -318,12 +319,12 @@
// CombinedOutput runs the command and returns its combined standard
// output and standard error.
-func (c *Cmd) CombinedOutput() ([]byte, os.Error) {
+func (c *Cmd) CombinedOutput() ([]byte, error) {
if c.Stdout != nil {
- return nil, os.NewError("exec: Stdout already set")
+ return nil, errors.New("exec: Stdout already set")
}
if c.Stderr != nil {
- return nil, os.NewError("exec: Stderr already set")
+ return nil, errors.New("exec: Stderr already set")
}
var b bytes.Buffer
c.Stdout = &b
@@ -334,12 +335,12 @@
// StdinPipe returns a pipe that will be connected to the command's
// standard input when the command starts.
-func (c *Cmd) StdinPipe() (io.WriteCloser, os.Error) {
+func (c *Cmd) StdinPipe() (io.WriteCloser, error) {
if c.Stdin != nil {
- return nil, os.NewError("exec: Stdin already set")
+ return nil, errors.New("exec: Stdin already set")
}
if c.Process != nil {
- return nil, os.NewError("exec: StdinPipe after process started")
+ return nil, errors.New("exec: StdinPipe after process started")
}
pr, pw, err := os.Pipe()
if err != nil {
@@ -354,12 +355,12 @@
// StdoutPipe returns a pipe that will be connected to the command's
// standard output when the command starts.
// The pipe will be closed automatically after Wait sees the command exit.
-func (c *Cmd) StdoutPipe() (io.ReadCloser, os.Error) {
+func (c *Cmd) StdoutPipe() (io.ReadCloser, error) {
if c.Stdout != nil {
- return nil, os.NewError("exec: Stdout already set")
+ return nil, errors.New("exec: Stdout already set")
}
if c.Process != nil {
- return nil, os.NewError("exec: StdoutPipe after process started")
+ return nil, errors.New("exec: StdoutPipe after process started")
}
pr, pw, err := os.Pipe()
if err != nil {
@@ -374,12 +375,12 @@
// StderrPipe returns a pipe that will be connected to the command's
// standard error when the command starts.
// The pipe will be closed automatically after Wait sees the command exit.
-func (c *Cmd) StderrPipe() (io.ReadCloser, os.Error) {
+func (c *Cmd) StderrPipe() (io.ReadCloser, error) {
if c.Stderr != nil {
- return nil, os.NewError("exec: Stderr already set")
+ return nil, errors.New("exec: Stderr already set")
}
if c.Process != nil {
- return nil, os.NewError("exec: StderrPipe after process started")
+ return nil, errors.New("exec: StderrPipe after process started")
}
pr, pw, err := os.Pipe()
if err != nil {
diff --git a/src/pkg/exec/exec_test.go b/src/pkg/exec/exec_test.go
index 3183919..6d5e893 100644
--- a/src/pkg/exec/exec_test.go
+++ b/src/pkg/exec/exec_test.go
@@ -82,7 +82,7 @@
// Test that exit values are returned correctly
err := helperCommand("exit", "42").Run()
if werr, ok := err.(*ExitError); ok {
- if s, e := werr.String(), "exit status 42"; s != e {
+ if s, e := werr.Error(), "exit status 42"; s != e {
t.Errorf("from exit 42 got exit %q, want %q", s, e)
}
} else {
@@ -91,7 +91,7 @@
}
func TestPipes(t *testing.T) {
- check := func(what string, err os.Error) {
+ check := func(what string, err error) {
if err != nil {
t.Fatalf("%s: %v", what, err)
}
@@ -224,7 +224,7 @@
bufr := bufio.NewReader(os.Stdin)
for {
line, _, err := bufr.ReadLine()
- if err == os.EOF {
+ if err == io.EOF {
break
} else if err != nil {
os.Exit(1)
diff --git a/src/pkg/exec/lp_plan9.go b/src/pkg/exec/lp_plan9.go
index e4751a4..d4ffc17 100644
--- a/src/pkg/exec/lp_plan9.go
+++ b/src/pkg/exec/lp_plan9.go
@@ -5,14 +5,15 @@
package exec
import (
+ "errors"
"os"
"strings"
)
// ErrNotFound is the error resulting if a path search failed to find an executable file.
-var ErrNotFound = os.NewError("executable file not found in $path")
+var ErrNotFound = errors.New("executable file not found in $path")
-func findExecutable(file string) os.Error {
+func findExecutable(file string) error {
d, err := os.Stat(file)
if err != nil {
return err
@@ -27,7 +28,7 @@
// in the directories named by the path environment variable.
// If file begins with "/", "#", "./", or "../", it is tried
// directly and the path is not consulted.
-func LookPath(file string) (string, os.Error) {
+func LookPath(file string) (string, error) {
// skip the path lookup for these prefixes
skip := []string{"/", "#", "./", "../"}
diff --git a/src/pkg/exec/lp_unix.go b/src/pkg/exec/lp_unix.go
index 0cd19e7..d234641 100644
--- a/src/pkg/exec/lp_unix.go
+++ b/src/pkg/exec/lp_unix.go
@@ -7,14 +7,15 @@
package exec
import (
+ "errors"
"os"
"strings"
)
// ErrNotFound is the error resulting if a path search failed to find an executable file.
-var ErrNotFound = os.NewError("executable file not found in $PATH")
+var ErrNotFound = errors.New("executable file not found in $PATH")
-func findExecutable(file string) os.Error {
+func findExecutable(file string) error {
d, err := os.Stat(file)
if err != nil {
return err
@@ -28,7 +29,7 @@
// LookPath searches for an executable binary named file
// in the directories named by the PATH environment variable.
// If file contains a slash, it is tried directly and the PATH is not consulted.
-func LookPath(file string) (string, os.Error) {
+func LookPath(file string) (string, error) {
// NOTE(rsc): I wish we could use the Plan 9 behavior here
// (only bypass the path if file begins with / or ./ or ../)
// but that would not match all the Unix shells.
diff --git a/src/pkg/exec/lp_windows.go b/src/pkg/exec/lp_windows.go
index 7581088..db32623 100644
--- a/src/pkg/exec/lp_windows.go
+++ b/src/pkg/exec/lp_windows.go
@@ -5,14 +5,15 @@
package exec
import (
+ "errors"
"os"
"strings"
)
// ErrNotFound is the error resulting if a path search failed to find an executable file.
-var ErrNotFound = os.NewError("executable file not found in %PATH%")
+var ErrNotFound = errors.New("executable file not found in %PATH%")
-func chkStat(file string) os.Error {
+func chkStat(file string) error {
d, err := os.Stat(file)
if err != nil {
return err
@@ -23,7 +24,7 @@
return os.EPERM
}
-func findExecutable(file string, exts []string) (string, os.Error) {
+func findExecutable(file string, exts []string) (string, error) {
if len(exts) == 0 {
return file, chkStat(file)
}
@@ -41,7 +42,7 @@
return ``, os.ENOENT
}
-func LookPath(file string) (f string, err os.Error) {
+func LookPath(file string) (f string, err error) {
x := os.Getenv(`PATHEXT`)
if x == `` {
x = `.COM;.EXE;.BAT;.CMD`