From 0fa3265fe14c775668fc8272f47adf4fbaa60bac Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 29 Jun 2021 16:31:18 -0700 Subject: [PATCH] os: change example to avoid deprecated function The IsNotExist function is deprecated; change package example to avoid it and use the recommended way instead. Fixes #46976 Change-Id: I3c301d0a89b6bda42184df314ba8418062ca39ee Reviewed-on: https://go-review.googlesource.com/c/go/+/331692 Trust: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor Reviewed-by: Robert Griesemer --- src/os/example_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/os/example_test.go b/src/os/example_test.go index 3adce517848..e8554b0b122 100644 --- a/src/os/example_test.go +++ b/src/os/example_test.go @@ -5,6 +5,7 @@ package os_test import ( + "errors" "fmt" "io/fs" "log" @@ -71,9 +72,9 @@ func ExampleFileMode() { } } -func ExampleIsNotExist() { +func ExampleErrNotExist() { filename := "a-nonexistent-file" - if _, err := os.Stat(filename); os.IsNotExist(err) { + if _, err := os.Stat(filename); errors.Is(err, fs.ErrNotExist) { fmt.Println("file does not exist") } // Output: