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/exp/sql/convert.go b/src/pkg/exp/sql/convert.go
index a35e0be..b1feef0 100644
--- a/src/pkg/exp/sql/convert.go
+++ b/src/pkg/exp/sql/convert.go
@@ -7,8 +7,8 @@
package sql
import (
+ "errors"
"fmt"
- "os"
"reflect"
"strconv"
)
@@ -16,7 +16,7 @@
// convertAssign copies to dest the value in src, converting it if possible.
// An error is returned if the copy would result in loss of information.
// dest should be a pointer type.
-func convertAssign(dest, src interface{}) os.Error {
+func convertAssign(dest, src interface{}) error {
// Common cases, without reflect. Fall through.
switch s := src.(type) {
case string:
@@ -56,7 +56,7 @@
dpv := reflect.ValueOf(dest)
if dpv.Kind() != reflect.Ptr {
- return os.NewError("destination not a pointer")
+ return errors.New("destination not a pointer")
}
dv := reflect.Indirect(dpv)
diff --git a/src/pkg/exp/sql/convert_test.go b/src/pkg/exp/sql/convert_test.go
index 8499918..f85ed99 100644
--- a/src/pkg/exp/sql/convert_test.go
+++ b/src/pkg/exp/sql/convert_test.go
@@ -68,7 +68,7 @@
err := convertAssign(ct.d, ct.s)
errstr := ""
if err != nil {
- errstr = err.String()
+ errstr = err.Error()
}
errf := func(format string, args ...interface{}) {
base := fmt.Sprintf("convertAssign #%d: for %v (%T) -> %T, ", n, ct.s, ct.s, ct.d)
diff --git a/src/pkg/exp/sql/driver/driver.go b/src/pkg/exp/sql/driver/driver.go
index 7508b19..52714e8 100644
--- a/src/pkg/exp/sql/driver/driver.go
+++ b/src/pkg/exp/sql/driver/driver.go
@@ -19,9 +19,7 @@
//
package driver
-import (
- "os"
-)
+import "errors"
// Driver is the interface that must be implemented by a database
// driver.
@@ -31,7 +29,7 @@
//
// The returned connection is only used by one goroutine at a
// time.
- Open(name string) (Conn, os.Error)
+ Open(name string) (Conn, error)
}
// Execer is an optional interface that may be implemented by a Driver
@@ -48,7 +46,7 @@
//
// All arguments are of a subset type as defined in the package docs.
type Execer interface {
- Exec(query string, args []interface{}) (Result, os.Error)
+ Exec(query string, args []interface{}) (Result, error)
}
// Conn is a connection to a database. It is not used concurrently
@@ -57,16 +55,16 @@
// Conn is assumed to be stateful.
type Conn interface {
// Prepare returns a prepared statement, bound to this connection.
- Prepare(query string) (Stmt, os.Error)
+ Prepare(query string) (Stmt, error)
// Close invalidates and potentially stops any current
// prepared statements and transactions, marking this
// connection as no longer in use. The driver may cache or
// close its underlying connection to its database.
- Close() os.Error
+ Close() error
// Begin starts and returns a new transaction.
- Begin() (Tx, os.Error)
+ Begin() (Tx, error)
}
// Result is the result of a query execution.
@@ -74,18 +72,18 @@
// LastInsertId returns the database's auto-generated ID
// after, for example, an INSERT into a table with primary
// key.
- LastInsertId() (int64, os.Error)
+ LastInsertId() (int64, error)
// RowsAffected returns the number of rows affected by the
// query.
- RowsAffected() (int64, os.Error)
+ RowsAffected() (int64, error)
}
// Stmt is a prepared statement. It is bound to a Conn and not
// used by multiple goroutines concurrently.
type Stmt interface {
// Close closes the statement.
- Close() os.Error
+ Close() error
// NumInput returns the number of placeholder parameters.
NumInput() int
@@ -93,11 +91,11 @@
// Exec executes a query that doesn't return rows, such
// as an INSERT or UPDATE. The args are all of a subset
// type as defined above.
- Exec(args []interface{}) (Result, os.Error)
+ Exec(args []interface{}) (Result, error)
// Exec executes a query that may return rows, such as a
// SELECT. The args of all of a subset type as defined above.
- Query(args []interface{}) (Rows, os.Error)
+ Query(args []interface{}) (Rows, error)
}
// ColumnConverter may be optionally implemented by Stmt if the
@@ -120,7 +118,7 @@
Columns() []string
// Close closes the rows iterator.
- Close() os.Error
+ Close() error
// Next is called to populate the next row of data into
// the provided slice. The provided slice will be the same
@@ -129,13 +127,13 @@
// The dest slice may be populated with only with values
// of subset types defined above, but excluding string.
// All string values must be converted to []byte.
- Next(dest []interface{}) os.Error
+ Next(dest []interface{}) error
}
// Tx is a transaction.
type Tx interface {
- Commit() os.Error
- Rollback() os.Error
+ Commit() error
+ Rollback() error
}
// RowsAffected implements Result for an INSERT or UPDATE operation
@@ -144,11 +142,11 @@
var _ Result = RowsAffected(0)
-func (RowsAffected) LastInsertId() (int64, os.Error) {
- return 0, os.NewError("no LastInsertId available")
+func (RowsAffected) LastInsertId() (int64, error) {
+ return 0, errors.New("no LastInsertId available")
}
-func (v RowsAffected) RowsAffected() (int64, os.Error) {
+func (v RowsAffected) RowsAffected() (int64, error) {
return int64(v), nil
}
@@ -160,10 +158,10 @@
var _ Result = ddlSuccess{}
-func (ddlSuccess) LastInsertId() (int64, os.Error) {
- return 0, os.NewError("no LastInsertId available after DDL statement")
+func (ddlSuccess) LastInsertId() (int64, error) {
+ return 0, errors.New("no LastInsertId available after DDL statement")
}
-func (ddlSuccess) RowsAffected() (int64, os.Error) {
- return 0, os.NewError("no RowsAffected available after DDL statement")
+func (ddlSuccess) RowsAffected() (int64, error) {
+ return 0, errors.New("no RowsAffected available after DDL statement")
}
diff --git a/src/pkg/exp/sql/driver/types.go b/src/pkg/exp/sql/driver/types.go
index 5521d53..9faf32f 100644
--- a/src/pkg/exp/sql/driver/types.go
+++ b/src/pkg/exp/sql/driver/types.go
@@ -6,7 +6,6 @@
import (
"fmt"
- "os"
"reflect"
"strconv"
)
@@ -14,7 +13,7 @@
// ValueConverter is the interface providing the ConvertValue method.
type ValueConverter interface {
// ConvertValue converts a value to a restricted subset type.
- ConvertValue(v interface{}) (interface{}, os.Error)
+ ConvertValue(v interface{}) (interface{}, error)
}
// Bool is a ValueConverter that converts input values to bools.
@@ -27,7 +26,7 @@
var _ ValueConverter = boolType{}
-func (boolType) ConvertValue(v interface{}) (interface{}, os.Error) {
+func (boolType) ConvertValue(v interface{}) (interface{}, error) {
return nil, fmt.Errorf("TODO(bradfitz): bool conversions")
}
@@ -39,7 +38,7 @@
var _ ValueConverter = int32Type{}
-func (int32Type) ConvertValue(v interface{}) (interface{}, os.Error) {
+func (int32Type) ConvertValue(v interface{}) (interface{}, error) {
rv := reflect.ValueOf(v)
switch rv.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
@@ -72,7 +71,7 @@
type stringType struct{}
-func (stringType) ConvertValue(v interface{}) (interface{}, os.Error) {
+func (stringType) ConvertValue(v interface{}) (interface{}, error) {
switch v.(type) {
case string, []byte:
return v, nil
@@ -137,7 +136,7 @@
var _ ValueConverter = defaultConverter{}
-func (defaultConverter) ConvertValue(v interface{}) (interface{}, os.Error) {
+func (defaultConverter) ConvertValue(v interface{}) (interface{}, error) {
if IsParameterSubsetType(v) {
return v, nil
}
diff --git a/src/pkg/exp/sql/fakedb_test.go b/src/pkg/exp/sql/fakedb_test.go
index c906185..289294b 100644
--- a/src/pkg/exp/sql/fakedb_test.go
+++ b/src/pkg/exp/sql/fakedb_test.go
@@ -5,9 +5,10 @@
package sql
import (
+ "errors"
"fmt"
+ "io"
"log"
- "os"
"strconv"
"strings"
"sync"
@@ -108,7 +109,7 @@
// Supports dsn forms:
// <dbname>
// <dbname>;wipe
-func (d *fakeDriver) Open(dsn string) (driver.Conn, os.Error) {
+func (d *fakeDriver) Open(dsn string) (driver.Conn, error) {
d.mu.Lock()
defer d.mu.Unlock()
d.openCount++
@@ -117,7 +118,7 @@
}
parts := strings.Split(dsn, ";")
if len(parts) < 1 {
- return nil, os.NewError("fakedb: no database name")
+ return nil, errors.New("fakedb: no database name")
}
name := parts[0]
db, ok := d.dbs[name]
@@ -134,7 +135,7 @@
db.tables = nil
}
-func (db *fakeDB) createTable(name string, columnNames, columnTypes []string) os.Error {
+func (db *fakeDB) createTable(name string, columnNames, columnTypes []string) error {
db.mu.Lock()
defer db.mu.Unlock()
if db.tables == nil {
@@ -175,33 +176,33 @@
return "", false
}
-func (c *fakeConn) Begin() (driver.Tx, os.Error) {
+func (c *fakeConn) Begin() (driver.Tx, error) {
if c.currTx != nil {
- return nil, os.NewError("already in a transaction")
+ return nil, errors.New("already in a transaction")
}
c.currTx = &fakeTx{c: c}
return c.currTx, nil
}
-func (c *fakeConn) Close() os.Error {
+func (c *fakeConn) Close() error {
if c.currTx != nil {
- return os.NewError("can't close; in a Transaction")
+ return errors.New("can't close; in a Transaction")
}
if c.db == nil {
- return os.NewError("can't close; already closed")
+ return errors.New("can't close; already closed")
}
c.db = nil
return nil
}
-func errf(msg string, args ...interface{}) os.Error {
- return os.NewError("fakedb: " + fmt.Sprintf(msg, args...))
+func errf(msg string, args ...interface{}) error {
+ return errors.New("fakedb: " + fmt.Sprintf(msg, args...))
}
// parts are table|selectCol1,selectCol2|whereCol=?,whereCol2=?
// (note that where where columns must always contain ? marks,
// just a limitation for fakedb)
-func (c *fakeConn) prepareSelect(stmt *fakeStmt, parts []string) (driver.Stmt, os.Error) {
+func (c *fakeConn) prepareSelect(stmt *fakeStmt, parts []string) (driver.Stmt, error) {
if len(parts) != 3 {
return nil, errf("invalid SELECT syntax with %d parts; want 3", len(parts))
}
@@ -228,7 +229,7 @@
}
// parts are table|col=type,col2=type2
-func (c *fakeConn) prepareCreate(stmt *fakeStmt, parts []string) (driver.Stmt, os.Error) {
+func (c *fakeConn) prepareCreate(stmt *fakeStmt, parts []string) (driver.Stmt, error) {
if len(parts) != 2 {
return nil, errf("invalid CREATE syntax with %d parts; want 2", len(parts))
}
@@ -245,7 +246,7 @@
}
// parts are table|col=?,col2=val
-func (c *fakeConn) prepareInsert(stmt *fakeStmt, parts []string) (driver.Stmt, os.Error) {
+func (c *fakeConn) prepareInsert(stmt *fakeStmt, parts []string) (driver.Stmt, error) {
if len(parts) != 2 {
return nil, errf("invalid INSERT syntax with %d parts; want 2", len(parts))
}
@@ -287,7 +288,7 @@
return stmt, nil
}
-func (c *fakeConn) Prepare(query string) (driver.Stmt, os.Error) {
+func (c *fakeConn) Prepare(query string) (driver.Stmt, error) {
if c.db == nil {
panic("nil c.db; conn = " + fmt.Sprintf("%#v", c))
}
@@ -317,11 +318,11 @@
return s.placeholderConverter[idx]
}
-func (s *fakeStmt) Close() os.Error {
+func (s *fakeStmt) Close() error {
return nil
}
-func (s *fakeStmt) Exec(args []interface{}) (driver.Result, os.Error) {
+func (s *fakeStmt) Exec(args []interface{}) (driver.Result, error) {
db := s.c.db
switch s.cmd {
case "WIPE":
@@ -339,7 +340,7 @@
return nil, fmt.Errorf("unimplemented statement Exec command type of %q", s.cmd)
}
-func (s *fakeStmt) execInsert(args []interface{}) (driver.Result, os.Error) {
+func (s *fakeStmt) execInsert(args []interface{}) (driver.Result, error) {
db := s.c.db
if len(args) != s.placeholders {
panic("error in pkg db; should only get here if size is correct")
@@ -375,7 +376,7 @@
return driver.RowsAffected(1), nil
}
-func (s *fakeStmt) Query(args []interface{}) (driver.Rows, os.Error) {
+func (s *fakeStmt) Query(args []interface{}) (driver.Rows, error) {
db := s.c.db
if len(args) != s.placeholders {
panic("error in pkg db; should only get here if size is correct")
@@ -438,12 +439,12 @@
return s.placeholders
}
-func (tx *fakeTx) Commit() os.Error {
+func (tx *fakeTx) Commit() error {
tx.c.currTx = nil
return nil
}
-func (tx *fakeTx) Rollback() os.Error {
+func (tx *fakeTx) Rollback() error {
tx.c.currTx = nil
return nil
}
@@ -455,7 +456,7 @@
closed bool
}
-func (rc *rowsCursor) Close() os.Error {
+func (rc *rowsCursor) Close() error {
rc.closed = true
return nil
}
@@ -464,13 +465,13 @@
return rc.cols
}
-func (rc *rowsCursor) Next(dest []interface{}) os.Error {
+func (rc *rowsCursor) Next(dest []interface{}) error {
if rc.closed {
- return os.NewError("fakedb: cursor is closed")
+ return errors.New("fakedb: cursor is closed")
}
rc.pos++
if rc.pos >= len(rc.rows) {
- return os.EOF // per interface spec
+ return io.EOF // per interface spec
}
for i, v := range rc.rows[rc.pos].cols {
// TODO(bradfitz): convert to subset types? naah, I
diff --git a/src/pkg/exp/sql/sql.go b/src/pkg/exp/sql/sql.go
index 7f0e0b2..4f1c539 100644
--- a/src/pkg/exp/sql/sql.go
+++ b/src/pkg/exp/sql/sql.go
@@ -7,8 +7,9 @@
package sql
import (
+ "errors"
"fmt"
- "os"
+ "io"
"runtime"
"sync"
@@ -50,7 +51,7 @@
}
// ScanInto implements the ScannerInto interface.
-func (ms *NullableString) ScanInto(value interface{}) os.Error {
+func (ms *NullableString) ScanInto(value interface{}) error {
if value == nil {
ms.String, ms.Valid = "", false
return nil
@@ -74,13 +75,13 @@
//
// An error should be returned if the value can not be stored
// without loss of information.
- ScanInto(value interface{}) os.Error
+ ScanInto(value interface{}) error
}
// ErrNoRows is returned by Scan when QueryRow doesn't return a
// row. In such a case, QueryRow returns a placeholder *Row value that
// defers this error until a Scan.
-var ErrNoRows = os.NewError("db: no rows in result set")
+var ErrNoRows = errors.New("db: no rows in result set")
// DB is a database handle. It's safe for concurrent use by multiple
// goroutines.
@@ -98,7 +99,7 @@
//
// Most users will open a database via a driver-specific connection
// helper function that returns a *DB.
-func Open(driverName, dataSourceName string) (*DB, os.Error) {
+func Open(driverName, dataSourceName string) (*DB, error) {
driver, ok := drivers[driverName]
if !ok {
return nil, fmt.Errorf("db: unknown driver %q (forgotten import?)", driverName)
@@ -114,7 +115,7 @@
}
// conn returns a newly-opened or cached driver.Conn
-func (db *DB) conn() (driver.Conn, os.Error) {
+func (db *DB) conn() (driver.Conn, error) {
db.mu.Lock()
if n := len(db.freeConn); n > 0 {
conn := db.freeConn[n-1]
@@ -154,7 +155,7 @@
}
// Prepare creates a prepared statement for later execution.
-func (db *DB) Prepare(query string) (*Stmt, os.Error) {
+func (db *DB) Prepare(query string) (*Stmt, error) {
// TODO: check if db.driver supports an optional
// driver.Preparer interface and call that instead, if so,
// otherwise we make a prepared statement that's bound
@@ -179,7 +180,7 @@
}
// Exec executes a query without returning any rows.
-func (db *DB) Exec(query string, args ...interface{}) (Result, os.Error) {
+func (db *DB) Exec(query string, args ...interface{}) (Result, error) {
// Optional fast path, if the driver implements driver.Execer.
if execer, ok := db.driver.(driver.Execer); ok {
resi, err := execer.Exec(query, args)
@@ -218,7 +219,7 @@
}
// Query executes a query that returns rows, typically a SELECT.
-func (db *DB) Query(query string, args ...interface{}) (*Rows, os.Error) {
+func (db *DB) Query(query string, args ...interface{}) (*Rows, error) {
stmt, err := db.Prepare(query)
if err != nil {
return nil, err
@@ -240,7 +241,7 @@
// Begin starts a transaction. The isolation level is dependent on
// the driver.
-func (db *DB) Begin() (*Tx, os.Error) {
+func (db *DB) Begin() (*Tx, error) {
// TODO(bradfitz): add another method for beginning a transaction
// at a specific isolation level.
panic(todo())
@@ -257,17 +258,17 @@
}
// Commit commits the transaction.
-func (tx *Tx) Commit() os.Error {
+func (tx *Tx) Commit() error {
panic(todo())
}
// Rollback aborts the transaction.
-func (tx *Tx) Rollback() os.Error {
+func (tx *Tx) Rollback() error {
panic(todo())
}
// Prepare creates a prepared statement.
-func (tx *Tx) Prepare(query string) (*Stmt, os.Error) {
+func (tx *Tx) Prepare(query string) (*Stmt, error) {
panic(todo())
}
@@ -278,7 +279,7 @@
}
// Query executes a query that returns rows, typically a SELECT.
-func (tx *Tx) Query(query string, args ...interface{}) (*Rows, os.Error) {
+func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error) {
panic(todo())
}
@@ -313,7 +314,7 @@
// Exec executes a prepared statement with the given arguments and
// returns a Result summarizing the effect of the statement.
-func (s *Stmt) Exec(args ...interface{}) (Result, os.Error) {
+func (s *Stmt) Exec(args ...interface{}) (Result, error) {
ci, si, err := s.connStmt()
if err != nil {
return nil, err
@@ -352,10 +353,10 @@
return result{resi}, nil
}
-func (s *Stmt) connStmt(args ...interface{}) (driver.Conn, driver.Stmt, os.Error) {
+func (s *Stmt) connStmt(args ...interface{}) (driver.Conn, driver.Stmt, error) {
s.mu.Lock()
if s.closed {
- return nil, nil, os.NewError("db: statement is closed")
+ return nil, nil, errors.New("db: statement is closed")
}
var cs connStmt
match := false
@@ -391,7 +392,7 @@
// Query executes a prepared query statement with the given arguments
// and returns the query results as a *Rows.
-func (s *Stmt) Query(args ...interface{}) (*Rows, os.Error) {
+func (s *Stmt) Query(args ...interface{}) (*Rows, error) {
ci, si, err := s.connStmt(args...)
if err != nil {
return nil, err
@@ -433,7 +434,7 @@
}
// Close closes the statement.
-func (s *Stmt) Close() os.Error {
+func (s *Stmt) Close() error {
s.mu.Lock()
defer s.mu.Unlock() // TODO(bradfitz): move this unlock after 'closed = true'?
if s.closed {
@@ -473,7 +474,7 @@
closed bool
lastcols []interface{}
- lasterr os.Error
+ lasterr error
}
// Next prepares the next result row for reading with the Scan method.
@@ -495,8 +496,8 @@
}
// Error returns the error, if any, that was encountered during iteration.
-func (rs *Rows) Error() os.Error {
- if rs.lasterr == os.EOF {
+func (rs *Rows) Error() error {
+ if rs.lasterr == io.EOF {
return nil
}
return rs.lasterr
@@ -506,15 +507,15 @@
// at by dest. If dest contains pointers to []byte, the slices should
// not be modified and should only be considered valid until the next
// call to Next or Scan.
-func (rs *Rows) Scan(dest ...interface{}) os.Error {
+func (rs *Rows) Scan(dest ...interface{}) error {
if rs.closed {
- return os.NewError("db: Rows closed")
+ return errors.New("db: Rows closed")
}
if rs.lasterr != nil {
return rs.lasterr
}
if rs.lastcols == nil {
- return os.NewError("db: Scan called without calling Next")
+ return errors.New("db: Scan called without calling Next")
}
if len(dest) != len(rs.lastcols) {
return fmt.Errorf("db: expected %d destination arguments in Scan, not %d", len(rs.lastcols), len(dest))
@@ -531,7 +532,7 @@
// Close closes the Rows, preventing further enumeration. If the
// end is encountered, the Rows are closed automatically. Close
// is idempotent.
-func (rs *Rows) Close() os.Error {
+func (rs *Rows) Close() error {
if rs.closed {
return nil
}
@@ -544,7 +545,7 @@
// Row is the result of calling QueryRow to select a single row.
type Row struct {
// One of these two will be non-nil:
- err os.Error // deferred error for easy chaining
+ err error // deferred error for easy chaining
rows *Rows
}
@@ -556,7 +557,7 @@
// If dest contains pointers to []byte, the slices should not be
// modified and should only be considered valid until the next call to
// Next or Scan.
-func (r *Row) Scan(dest ...interface{}) os.Error {
+func (r *Row) Scan(dest ...interface{}) error {
if r.err != nil {
return r.err
}
@@ -569,8 +570,8 @@
// A Result summarizes an executed SQL command.
type Result interface {
- LastInsertId() (int64, os.Error)
- RowsAffected() (int64, os.Error)
+ LastInsertId() (int64, error)
+ RowsAffected() (int64, error)
}
type result struct {
diff --git a/src/pkg/exp/sql/sql_test.go b/src/pkg/exp/sql/sql_test.go
index eaa0a90..eb1bb58 100644
--- a/src/pkg/exp/sql/sql_test.go
+++ b/src/pkg/exp/sql/sql_test.go
@@ -40,7 +40,7 @@
var age int
err := db.QueryRow("SELECT|people|age,name|age=?", 3).Scan(&age)
- if err == nil || !strings.Contains(err.String(), "expected 2 destination arguments") {
+ if err == nil || !strings.Contains(err.Error(), "expected 2 destination arguments") {
t.Errorf("expected error from wrong number of arguments; actually got: %v", err)
}
@@ -99,7 +99,7 @@
if err == nil {
t.Fatalf("expected error")
}
- if err.String() != `fakedb: invalid conversion to int32 from "bogusconversion"` {
+ if err.Error() != `fakedb: invalid conversion to int32 from "bogusconversion"` {
t.Errorf("unexpected error: %v", err)
}
}
@@ -135,7 +135,7 @@
_, err := stmt.Exec(et.args...)
errStr := ""
if err != nil {
- errStr = err.String()
+ errStr = err.Error()
}
if errStr != et.wantErr {
t.Errorf("stmt.Execute #%d: for %v, got error %q, want error %q",