From 7a2e0b5a91a7ff8102143ee7673f0cf692e16b82 Mon Sep 17 00:00:00 2001 From: kovan Date: Wed, 11 Mar 2026 13:15:25 +0100 Subject: [PATCH] os: update examples to use errors.Is instead of deprecated helpers The os.IsExist and os.IsNotExist functions predate errors.Is and their documentation recommends using errors.Is(err, fs.ErrExist) and errors.Is(err, fs.ErrNotExist) in new code. Update ExampleMkdir and ExampleUserConfigDir to follow this recommendation. Change-Id: I791a9dcac624abdcd35cbeba11640fc895f2706f --- src/os/example_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/example_test.go b/src/os/example_test.go index c507d46c46303a..900da6f690ba7c 100644 --- a/src/os/example_test.go +++ b/src/os/example_test.go @@ -246,7 +246,7 @@ func ExampleWriteFile() { func ExampleMkdir() { err := os.Mkdir("testdir", 0750) - if err != nil && !os.IsExist(err) { + if err != nil && !errors.Is(err, fs.ErrExist) { log.Fatal(err) } err = os.WriteFile("testdir/testfile.txt", []byte("Hello, Gophers!"), 0660) @@ -365,7 +365,7 @@ func ExampleUserConfigDir() { configPath = filepath.Join(dir, "ExampleUserConfigDir", "example.conf") var err error origConfig, err = os.ReadFile(configPath) - if err != nil && !os.IsNotExist(err) { + if err != nil && !errors.Is(err, fs.ErrNotExist) { // The user has a config file but we couldn't read it. // Report the error instead of ignoring their configuration. log.Fatal(err)