Skip to content

Commit 3cb3bb8

Browse files
committed
re
1 parent 26137be commit 3cb3bb8

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

src/io/fs/readdir_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ func TestFileInfoToDirEntry(t *testing.T) {
9393
}
9494
}
9595

96-
func TestReadDirPath(t *testing.T) {
97-
errorPath := func(err error) string {
98-
var perr *PathError
99-
if !errors.As(err, &perr) {
100-
return ""
101-
}
102-
return perr.Path
96+
func errorPath(err error) string {
97+
var perr *PathError
98+
if !errors.As(err, &perr) {
99+
return ""
103100
}
101+
return perr.Path
102+
}
103+
104+
func TestReadDirPath(t *testing.T) {
104105
fsys := os.DirFS(t.TempDir())
105106
_, err1 := ReadDir(fsys, "non-existent")
106107
_, err2 := ReadDir(struct{ FS }{fsys}, "non-existent")

src/io/fs/readfile_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package fs_test
66

77
import (
8-
"errors"
98
. "io/fs"
109
"os"
1110
"testing"
@@ -61,13 +60,6 @@ func TestReadFile(t *testing.T) {
6160
}
6261

6362
func TestReadFilePath(t *testing.T) {
64-
errorPath := func(err error) string {
65-
var perr *PathError
66-
if !errors.As(err, &perr) {
67-
return ""
68-
}
69-
return perr.Path
70-
}
7163
fsys := os.DirFS(t.TempDir())
7264
_, err1 := ReadFile(fsys, "non-existent")
7365
_, err2 := ReadFile(struct{ FS }{fsys}, "non-existent")

src/os/file.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,10 @@ func (dir dirFS) ReadFile(name string) ([]byte, error) {
692692
}
693693
b, err := ReadFile(fullname)
694694
if err != nil {
695-
// See comment in dirFS.Open.
696-
err.(*PathError).Path = name
695+
if e, ok := err.(*PathError); ok {
696+
// See comment in dirFS.Open.
697+
e.Path = name
698+
}
697699
return nil, err
698700
}
699701
return b, nil
@@ -708,8 +710,10 @@ func (dir dirFS) ReadDir(name string) ([]DirEntry, error) {
708710
}
709711
entries, err := ReadDir(fullname)
710712
if err != nil {
711-
// See comment in dirFS.Open.
712-
err.(*PathError).Path = name
713+
if e, ok := err.(*PathError); ok {
714+
// See comment in dirFS.Open.
715+
e.Path = name
716+
}
713717
return nil, err
714718
}
715719
return entries, nil

0 commit comments

Comments
 (0)