mirror of https://github.com/golang/go.git
improvements for error handling
This commit is contained in:
parent
6715bf3be8
commit
dbbbe96fd5
|
|
@ -78,9 +78,8 @@ func (d Dir) Open(name string) (File, error) {
|
|||
if dir == "" {
|
||||
dir = "."
|
||||
}
|
||||
fi, err := os.Stat(dir)
|
||||
if err != nil || !fi.IsDir() {
|
||||
return nil, errors.New("http: invalid directory path")
|
||||
if fi, _ := os.Stat(dir); fi != nil && !fi.IsDir() {
|
||||
return nil, errors.New("http: attempting to traverse a non-directory")
|
||||
}
|
||||
fullName := filepath.Join(dir, path)
|
||||
f, err := os.Open(fullName)
|
||||
|
|
|
|||
|
|
@ -1689,8 +1689,8 @@ func testFileServerDirWithRootFile(t *testing.T, mode testMode) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := res.StatusCode; s != StatusInternalServerError {
|
||||
t.Errorf("got %q, want 500", s)
|
||||
if g, w := res.StatusCode, StatusInternalServerError; g != w {
|
||||
t.Errorf("StatusCode mismatch: got %d, want: %d", g, w)
|
||||
}
|
||||
res.Body.Close()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue