From b004144aadfb065d1b4a94d52c056f73a2724d84 Mon Sep 17 00:00:00 2001 From: alliasgher Date: Tue, 14 Apr 2026 11:01:08 +0500 Subject: [PATCH] file: make ErrTimeout unwrap os.ErrDeadlineExceeded timeoutError.Unwrap returns os.ErrDeadlineExceeded so that callers can use errors.Is(err, os.ErrDeadlineExceeded) for portability with the standard library and other packages that check for deadline errors. The ErrTimeout sentinel value and its Error/Timeout/Temporary methods are unchanged, so this is fully backwards compatible. Fixes #321 Signed-off-by: alliasgher --- file.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/file.go b/file.go index f382137..13a23dc 100644 --- a/file.go +++ b/file.go @@ -5,6 +5,7 @@ package winio import ( "errors" "io" + "os" "runtime" "sync" "sync/atomic" @@ -31,6 +32,10 @@ func (*timeoutError) Error() string { return "i/o timeout" } func (*timeoutError) Timeout() bool { return true } func (*timeoutError) Temporary() bool { return true } +// Unwrap returns os.ErrDeadlineExceeded so that errors.Is(err, os.ErrDeadlineExceeded) +// returns true for ErrTimeout, enabling interoperability with the standard library. +func (*timeoutError) Unwrap() error { return os.ErrDeadlineExceeded } + type timeoutChan chan struct{} var ioInitOnce sync.Once