diff options
author | Russ Cox <rsc@golang.org> | 2011-11-01 22:06:05 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-11-01 22:06:05 -0400 |
commit | bff16976d902e297999e2813ead7f161ab619f18 (patch) | |
tree | a72976dffc1751229bb1f25a64290af6928e9be6 /src/cmd/godoc | |
parent | 35b030f60c6ba41d1f003cfca5cca64e025a51e8 (diff) | |
download | go-bff16976d902e297999e2813ead7f161ab619f18.tar.gz |
non-pkg: gofix -r error -force=error
R=golang-dev, iant, r, r
CC=golang-dev
http://codereview.appspot.com/5307066
Diffstat (limited to 'src/cmd/godoc')
-rw-r--r-- | src/cmd/godoc/appinit.go | 3 | ||||
-rw-r--r-- | src/cmd/godoc/codewalk.go | 19 | ||||
-rw-r--r-- | src/cmd/godoc/filesystem.go | 18 | ||||
-rw-r--r-- | src/cmd/godoc/godoc.go | 20 | ||||
-rw-r--r-- | src/cmd/godoc/httpzip.go | 14 | ||||
-rw-r--r-- | src/cmd/godoc/index.go | 16 | ||||
-rw-r--r-- | src/cmd/godoc/main.go | 7 | ||||
-rw-r--r-- | src/cmd/godoc/parser.go | 7 | ||||
-rw-r--r-- | src/cmd/godoc/utils.go | 2 | ||||
-rw-r--r-- | src/cmd/godoc/zip.go | 13 |
10 files changed, 59 insertions, 60 deletions
diff --git a/src/cmd/godoc/appinit.go b/src/cmd/godoc/appinit.go index 355d638b0..37c55451a 100644 --- a/src/cmd/godoc/appinit.go +++ b/src/cmd/godoc/appinit.go @@ -11,11 +11,10 @@ import ( "archive/zip" "http" "log" - "os" "path" ) -func serveError(w http.ResponseWriter, r *http.Request, relpath string, err os.Error) { +func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) { contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path! w.WriteHeader(http.StatusNotFound) servePage(w, "File "+relpath, "", "", contents) diff --git a/src/cmd/godoc/codewalk.go b/src/cmd/godoc/codewalk.go index 39f1fd5cb..6f25769a3 100644 --- a/src/cmd/godoc/codewalk.go +++ b/src/cmd/godoc/codewalk.go @@ -13,6 +13,7 @@ package main import ( + "errors" "fmt" "http" "io" @@ -84,7 +85,7 @@ type Codestep struct { XML string `xml:"innerxml"` // Derived from Src; not in XML. - Err os.Error + Err error File string Lo int LoByte int @@ -107,7 +108,7 @@ func (st *Codestep) String() string { } // loadCodewalk reads a codewalk from the named XML file. -func loadCodewalk(filename string) (*Codewalk, os.Error) { +func loadCodewalk(filename string) (*Codewalk, error) { f, err := fs.Open(filename) if err != nil { return nil, err @@ -252,7 +253,7 @@ func codewalkFileprint(w http.ResponseWriter, r *http.Request, f string) { // It returns the lo and hi byte offset of the matched region within data. // See http://plan9.bell-labs.com/sys/doc/sam/sam.html Table II // for details on the syntax. -func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err os.Error) { +func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err error) { var ( dir byte prevc byte @@ -264,7 +265,7 @@ func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err os.Er c := addr[0] switch c { default: - err = os.NewError("invalid address syntax near " + string(c)) + err = errors.New("invalid address syntax near " + string(c)) case ',': if len(addr) == 1 { hi = len(data) @@ -348,7 +349,7 @@ func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err os.Er // (or characters) after hi. Applying -n (or -#n) means to back up n lines // (or characters) before lo. // The return value is the new lo, hi. -func addrNumber(data []byte, lo, hi int, dir byte, n int, charOffset bool) (int, int, os.Error) { +func addrNumber(data []byte, lo, hi int, dir byte, n int, charOffset bool) (int, int, error) { switch dir { case 0: lo = 0 @@ -424,13 +425,13 @@ func addrNumber(data []byte, lo, hi int, dir byte, n int, charOffset bool) (int, } } - return 0, 0, os.NewError("address out of range") + return 0, 0, errors.New("address out of range") } // addrRegexp searches for pattern in the given direction starting at lo, hi. // The direction dir is '+' (search forward from hi) or '-' (search backward from lo). // Backward searches are unimplemented. -func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, os.Error) { +func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, error) { re, err := regexp.Compile(pattern) if err != nil { return 0, 0, err @@ -438,7 +439,7 @@ func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, os if dir == '-' { // Could implement reverse search using binary search // through file, but that seems like overkill. - return 0, 0, os.NewError("reverse search not implemented") + return 0, 0, errors.New("reverse search not implemented") } m := re.FindIndex(data[hi:]) if len(m) > 0 { @@ -449,7 +450,7 @@ func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, os m = re.FindIndex(data) } if len(m) == 0 { - return 0, 0, os.NewError("no match for " + pattern) + return 0, 0, errors.New("no match for " + pattern) } return m[0], m[1], nil } diff --git a/src/cmd/godoc/filesystem.go b/src/cmd/godoc/filesystem.go index 011977af9..ece9ebbf3 100644 --- a/src/cmd/godoc/filesystem.go +++ b/src/cmd/godoc/filesystem.go @@ -27,14 +27,14 @@ type FileInfo interface { // The FileSystem interface specifies the methods godoc is using // to access the file system for which it serves documentation. type FileSystem interface { - Open(path string) (io.ReadCloser, os.Error) - Lstat(path string) (FileInfo, os.Error) - Stat(path string) (FileInfo, os.Error) - ReadDir(path string) ([]FileInfo, os.Error) + Open(path string) (io.ReadCloser, error) + Lstat(path string) (FileInfo, error) + Stat(path string) (FileInfo, error) + ReadDir(path string) ([]FileInfo, error) } // ReadFile reads the file named by path from fs and returns the contents. -func ReadFile(fs FileSystem, path string) ([]byte, os.Error) { +func ReadFile(fs FileSystem, path string) ([]byte, error) { rc, err := fs.Open(path) if err != nil { return nil, err @@ -71,7 +71,7 @@ func (fi osFI) Mtime_ns() int64 { // osFS is the OS-specific implementation of FileSystem type osFS struct{} -func (osFS) Open(path string) (io.ReadCloser, os.Error) { +func (osFS) Open(path string) (io.ReadCloser, error) { f, err := os.Open(path) if err != nil { return nil, err @@ -86,17 +86,17 @@ func (osFS) Open(path string) (io.ReadCloser, os.Error) { return f, nil } -func (osFS) Lstat(path string) (FileInfo, os.Error) { +func (osFS) Lstat(path string) (FileInfo, error) { fi, err := os.Lstat(path) return osFI{fi}, err } -func (osFS) Stat(path string) (FileInfo, os.Error) { +func (osFS) Stat(path string) (FileInfo, error) { fi, err := os.Stat(path) return osFI{fi}, err } -func (osFS) ReadDir(path string) ([]FileInfo, os.Error) { +func (osFS) ReadDir(path string) ([]FileInfo, error) { l0, err := ioutil.ReadDir(path) // l0 is sorted if err != nil { return nil, err diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index d436898a2..0d82a1504 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -148,7 +148,7 @@ func getPathFilter() func(string) bool { // readDirList reads a file containing a newline-separated list // of directory paths and returns the list of paths. -func readDirList(filename string) ([]string, os.Error) { +func readDirList(filename string) ([]string, error) { contents, err := ReadFile(fs, filename) if err != nil { return nil, err @@ -299,7 +299,7 @@ type tconv struct { indent int // valid if state == indenting } -func (p *tconv) writeIndent() (err os.Error) { +func (p *tconv) writeIndent() (err error) { i := p.indent for i >= len(spaces) { i -= len(spaces) @@ -314,7 +314,7 @@ func (p *tconv) writeIndent() (err os.Error) { return } -func (p *tconv) Write(data []byte) (n int, err os.Error) { +func (p *tconv) Write(data []byte) (n int, err error) { if len(data) == 0 { return } @@ -855,7 +855,7 @@ type PageInfo struct { Dirs *DirList // nil if no directory information DirTime int64 // directory time stamp in seconds since epoch IsPkg bool // false if this is not documenting a real package - Err os.Error // directory read error or nil + Err error // directory read error or nil } func (info *PageInfo) IsEmpty() bool { @@ -869,7 +869,7 @@ type httpHandler struct { } // fsReadDir implements ReadDir for the go/build package. -func fsReadDir(dir string) ([]*os.FileInfo, os.Error) { +func fsReadDir(dir string) ([]*os.FileInfo, error) { fi, err := fs.ReadDir(dir) if err != nil { return nil, err @@ -888,7 +888,7 @@ func fsReadDir(dir string) ([]*os.FileInfo, os.Error) { } // fsReadFile implements ReadFile for the go/build package. -func fsReadFile(dir, name string) (path string, data []byte, err os.Error) { +func fsReadFile(dir, name string) (path string, data []byte, err error) { path = filepath.Join(dir, name) data, err = ReadFile(fs, path) return @@ -1172,12 +1172,12 @@ func lookup(query string) (result SearchResult) { index := index.(*Index) // identifier search - var err os.Error + var err error result.Pak, result.Hit, result.Alt, err = index.Lookup(query) if err != nil && *maxResults <= 0 { // ignore the error if full text search is enabled // since the query may be a valid regular expression - result.Alert = "Error in query string: " + err.String() + result.Alert = "Error in query string: " + err.Error() return } @@ -1185,7 +1185,7 @@ func lookup(query string) (result SearchResult) { if *maxResults > 0 && query != "" { rx, err := regexp.Compile(query) if err != nil { - result.Alert = "Error in query regular expression: " + err.String() + result.Alert = "Error in query regular expression: " + err.Error() return } // If we get maxResults+1 results we know that there are more than @@ -1280,7 +1280,7 @@ func fsDirnames() <-chan string { return c } -func readIndex(filenames string) os.Error { +func readIndex(filenames string) error { matches, err := filepath.Glob(filenames) if err != nil { return err diff --git a/src/cmd/godoc/httpzip.go b/src/cmd/godoc/httpzip.go index cb8322ee4..3e25b6473 100644 --- a/src/cmd/godoc/httpzip.go +++ b/src/cmd/godoc/httpzip.go @@ -50,7 +50,7 @@ type httpZipFile struct { list zipList } -func (f *httpZipFile) Close() os.Error { +func (f *httpZipFile) Close() error { if f.info.IsRegular() { return f.ReadCloser.Close() } @@ -58,11 +58,11 @@ func (f *httpZipFile) Close() os.Error { return nil } -func (f *httpZipFile) Stat() (*os.FileInfo, os.Error) { +func (f *httpZipFile) Stat() (*os.FileInfo, error) { return &f.info, nil } -func (f *httpZipFile) Readdir(count int) ([]os.FileInfo, os.Error) { +func (f *httpZipFile) Readdir(count int) ([]os.FileInfo, error) { var list []os.FileInfo dirname := f.path + "/" prevname := "" @@ -106,13 +106,13 @@ func (f *httpZipFile) Readdir(count int) ([]os.FileInfo, os.Error) { } if count >= 0 && len(list) == 0 { - return nil, os.EOF + return nil, io.EOF } return list, nil } -func (f *httpZipFile) Seek(offset int64, whence int) (int64, os.Error) { +func (f *httpZipFile) Seek(offset int64, whence int) (int64, error) { return 0, fmt.Errorf("Seek not implemented for zip file entry: %s", f.info.Name) } @@ -123,7 +123,7 @@ type httpZipFS struct { root string } -func (fs *httpZipFS) Open(name string) (http.File, os.Error) { +func (fs *httpZipFS) Open(name string) (http.File, error) { // fs.root does not start with '/'. path := path.Join(fs.root, name) // path is clean index, exact := fs.list.lookup(path) @@ -165,7 +165,7 @@ func (fs *httpZipFS) Open(name string) (http.File, os.Error) { }, nil } -func (fs *httpZipFS) Close() os.Error { +func (fs *httpZipFS) Close() error { fs.list = nil return fs.ReadCloser.Close() } diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go index 4f687ea83..68d1abe64 100644 --- a/src/cmd/godoc/index.go +++ b/src/cmd/godoc/index.go @@ -40,6 +40,7 @@ package main import ( "bufio" "bytes" + "errors" "go/ast" "go/parser" "go/token" @@ -47,7 +48,6 @@ import ( "gob" "index/suffixarray" "io" - "os" "path/filepath" "regexp" "sort" @@ -841,16 +841,16 @@ type fileIndex struct { Fulltext bool } -func (x *fileIndex) Write(w io.Writer) os.Error { +func (x *fileIndex) Write(w io.Writer) error { return gob.NewEncoder(w).Encode(x) } -func (x *fileIndex) Read(r io.Reader) os.Error { +func (x *fileIndex) Read(r io.Reader) error { return gob.NewDecoder(r).Decode(x) } // Write writes the index x to w. -func (x *Index) Write(w io.Writer) os.Error { +func (x *Index) Write(w io.Writer) error { fulltext := false if x.suffixes != nil { fulltext = true @@ -877,7 +877,7 @@ func (x *Index) Write(w io.Writer) os.Error { // Read reads the index from r into x; x must not be nil. // If r does not also implement io.ByteReader, it will be wrapped in a bufio.Reader. -func (x *Index) Read(r io.Reader) os.Error { +func (x *Index) Read(r io.Reader) error { // We use the ability to read bytes as a plausible surrogate for buffering. if _, ok := r.(io.ByteReader); !ok { r = bufio.NewReader(r) @@ -934,13 +934,13 @@ func isIdentifier(s string) bool { // identifier, Lookup returns a list of packages, a LookupResult, and a // list of alternative spellings, if any. Any and all results may be nil. // If the query syntax is wrong, an error is reported. -func (x *Index) Lookup(query string) (paks HitList, match *LookupResult, alt *AltWords, err os.Error) { +func (x *Index) Lookup(query string) (paks HitList, match *LookupResult, alt *AltWords, err error) { ss := strings.Split(query, ".") // check query syntax for _, s := range ss { if !isIdentifier(s) { - err = os.NewError("all query parts must be identifiers") + err = errors.New("all query parts must be identifiers") return } } @@ -968,7 +968,7 @@ func (x *Index) Lookup(query string) (paks HitList, match *LookupResult, alt *Al } default: - err = os.NewError("query is not a (qualified) identifier") + err = errors.New("query is not a (qualified) identifier") } return diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go index d05e03e0b..1a8db4708 100644 --- a/src/cmd/godoc/main.go +++ b/src/cmd/godoc/main.go @@ -28,6 +28,7 @@ package main import ( "archive/zip" "bytes" + "errors" _ "expvar" // to serve /debug/vars "flag" "fmt" @@ -74,7 +75,7 @@ var ( query = flag.Bool("q", false, "arguments are considered search queries") ) -func serveError(w http.ResponseWriter, r *http.Request, relpath string, err os.Error) { +func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) { contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path! w.WriteHeader(http.StatusNotFound) servePage(w, "File "+relpath, "", "", contents) @@ -163,7 +164,7 @@ func loggingHandler(h http.Handler) http.Handler { }) } -func remoteSearch(query string) (res *http.Response, err os.Error) { +func remoteSearch(query string) (res *http.Response, err error) { search := "/search?f=text&q=" + url.QueryEscape(query) // list of addresses to try @@ -188,7 +189,7 @@ func remoteSearch(query string) (res *http.Response, err os.Error) { } if err == nil && res.StatusCode != http.StatusOK { - err = os.NewError(res.Status) + err = errors.New(res.Status) } return diff --git a/src/cmd/godoc/parser.go b/src/cmd/godoc/parser.go index a2920539f..7597a00e7 100644 --- a/src/cmd/godoc/parser.go +++ b/src/cmd/godoc/parser.go @@ -13,11 +13,10 @@ import ( "go/ast" "go/parser" "go/token" - "os" "path/filepath" ) -func parseFile(fset *token.FileSet, filename string, mode uint) (*ast.File, os.Error) { +func parseFile(fset *token.FileSet, filename string, mode uint) (*ast.File, error) { src, err := ReadFile(fs, filename) if err != nil { return nil, err @@ -25,7 +24,7 @@ func parseFile(fset *token.FileSet, filename string, mode uint) (*ast.File, os.E return parser.ParseFile(fset, filename, src, mode) } -func parseFiles(fset *token.FileSet, filenames []string) (pkgs map[string]*ast.Package, first os.Error) { +func parseFiles(fset *token.FileSet, filenames []string) (pkgs map[string]*ast.Package, first error) { pkgs = make(map[string]*ast.Package) for _, filename := range filenames { file, err := parseFile(fset, filename, parser.ParseComments) @@ -48,7 +47,7 @@ func parseFiles(fset *token.FileSet, filenames []string) (pkgs map[string]*ast.P return } -func parseDir(fset *token.FileSet, path string, filter func(FileInfo) bool) (map[string]*ast.Package, os.Error) { +func parseDir(fset *token.FileSet, path string, filter func(FileInfo) bool) (map[string]*ast.Package, error) { list, err := fs.ReadDir(path) if err != nil { return nil, err diff --git a/src/cmd/godoc/utils.go b/src/cmd/godoc/utils.go index 11e46aee5..9ab5f8335 100644 --- a/src/cmd/godoc/utils.go +++ b/src/cmd/godoc/utils.go @@ -93,7 +93,7 @@ func canonicalizePaths(list []string, filter func(path string) bool) []string { // writeFileAtomically writes data to a temporary file and then // atomically renames that file to the file named by filename. // -func writeFileAtomically(filename string, data []byte) os.Error { +func writeFileAtomically(filename string, data []byte) error { // TODO(gri) this won't work on appengine f, err := ioutil.TempFile(filepath.Split(filename)) if err != nil { diff --git a/src/cmd/godoc/zip.go b/src/cmd/godoc/zip.go index 86cd79b17..201214222 100644 --- a/src/cmd/godoc/zip.go +++ b/src/cmd/godoc/zip.go @@ -22,7 +22,6 @@ import ( "archive/zip" "fmt" "io" - "os" "path" "sort" "strings" @@ -66,7 +65,7 @@ type zipFS struct { list zipList } -func (fs *zipFS) Close() os.Error { +func (fs *zipFS) Close() error { fs.list = nil return fs.ReadCloser.Close() } @@ -79,7 +78,7 @@ func zipPath(name string) string { return name[1:] // strip leading '/' } -func (fs *zipFS) stat(abspath string) (int, zipFI, os.Error) { +func (fs *zipFS) stat(abspath string) (int, zipFI, error) { i, exact := fs.list.lookup(abspath) if i < 0 { // abspath has leading '/' stripped - print it explicitly @@ -93,7 +92,7 @@ func (fs *zipFS) stat(abspath string) (int, zipFI, os.Error) { return i, zipFI{name, file}, nil } -func (fs *zipFS) Open(abspath string) (io.ReadCloser, os.Error) { +func (fs *zipFS) Open(abspath string) (io.ReadCloser, error) { _, fi, err := fs.stat(zipPath(abspath)) if err != nil { return nil, err @@ -104,17 +103,17 @@ func (fs *zipFS) Open(abspath string) (io.ReadCloser, os.Error) { return fi.file.Open() } -func (fs *zipFS) Lstat(abspath string) (FileInfo, os.Error) { +func (fs *zipFS) Lstat(abspath string) (FileInfo, error) { _, fi, err := fs.stat(zipPath(abspath)) return fi, err } -func (fs *zipFS) Stat(abspath string) (FileInfo, os.Error) { +func (fs *zipFS) Stat(abspath string) (FileInfo, error) { _, fi, err := fs.stat(zipPath(abspath)) return fi, err } -func (fs *zipFS) ReadDir(abspath string) ([]FileInfo, os.Error) { +func (fs *zipFS) ReadDir(abspath string) ([]FileInfo, error) { path := zipPath(abspath) i, fi, err := fs.stat(path) if err != nil { |