Skip to content

Commit

Permalink
path/filepath: change example to print the correct path on failure
Browse files Browse the repository at this point in the history
This change makes errors in the example code a bit better, as it's no use to show the root dir when an error occurs walking a subdirectory or file.

Change-Id: I546276e9b151fabba5357258f03bfbd47a508201
GitHub-Last-Rev: 398c1ee
GitHub-Pull-Request: golang#24536
Reviewed-on: https://go-review.googlesource.com/102535
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
diamondo25 authored and bradfitz committed Mar 26, 2018
1 parent 665af04 commit 683e2fd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/path/filepath/example_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ func ExampleJoin() {
// a/b/c
// a/b/c
}

func ExampleWalk() {
dir := "dir/to/walk"
subDirToSkip := "skip" // dir/to/walk/skip

err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", dir, err)
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
return err
}
if info.IsDir() && info.Name() == subDirToSkip {
Expand Down

0 comments on commit 683e2fd

Please sign in to comment.