← Back to Pull requests

improve interoperability with stdlib sentinel errors and deprecate aliases #392

Merged
thaJeztah merged 6 files (120 lines) on Oct 05, 2026 17:40 UTC
View on GitHub
thaJeztah thaJeztah commented on Oct 01, 2026 09:50 UTC
Author

  • fixes https://github.com/microsoft/go-winio/issues/321

  • supersedes, closes https://github.com/microsoft/go-winio/pull/353

  • relates to / updates https://github.com/microsoft/go-winio/pull/242
  • deprecate ErrPipeListenerClosed in favor of net.ErrClosed

    This error was made an alias in 02e8aff16e653a6639ae0c91b566abd4a0129a4f.
    Deprecate the alias in favor of stdlib.

    updates 02e8aff16e653a6639ae0c91b566abd4a0129a4f

    deprecate ErrFileClosed in favor of os.ErrClosed

    ErrFileClosed represents the same condition as os.ErrClosed. Use the
    standard library sentinel directly and deprecate the package-specific
    name.

    This also allows callers to consistently use errors.Is(err, os.ErrClosed)
    for operations on closed files.

    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.

    remove errPipeWriteClosed in favor of io.ErrClosedPipe

    Replace the private errPipeWriteClosed error with io.ErrClosedPipe.

    The previous error was not exported, so callers could not reliably use it
    as a sentinel. Its error string was technically observable, but a search
    did not find consumers depending on that specific message.

    Using io.ErrClosedPipe aligns this case with the standard library and gives
    callers a stable error they can identify with errors.Is.

    Diff: 120 lines (+91 / -29) across 6 files Reviewer: jterry75 Review duration: 6230m
    All Vouch review confidence checks passed
    Residual risk 0.08 = Change Risk (0.39) × (1 − Review Confidence (0.80)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 120 lines diff across 6 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.69 · 5 substantive comment(s)
    0.69
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    80%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.287
    Real PR Conversation Timeline
    8 items
    thaJeztah thaJeztah commented on Oct 01, 2026 09:56 UTC
    Author

    cc @jterry75 PTAL 🤗

    thaJeztah thaJeztah commented on code on Oct 01, 2026 10:00 UTC
    Code Review
    file.go:1
    @@ -20,16 +21,33 @@ import (
     //sys setFileCompletionNotificationModes(h windows.Handle, flags uint8) (err error) = SetFileCompletionNotificationModes
     //sys wsaGetOverlappedResult(h windows.Handle, o *windows.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) = ws2_32.WSAGetOverlappedResult
     
    -var (
    -	ErrFileClosed = errors.New("file has already been closed")
    -	ErrTimeout    = &timeoutError{}
    -)
    -
    +// ErrFileClosed is returned when an operation is performed on a closed file.
    +//
    +// Deprecated: use [os.ErrClosed] instead.
    +var ErrFileClosed = os.ErrClosed
    +
    +// ErrTimeout is returned when an I/O operation exceeds its deadline.
    +//
    +// It matches both [context.DeadlineExceeded] and [os.ErrDeadlineExceeded]
    +// with [errors.Is].
    +var ErrTimeout error = &timeoutError{}
    +
    +// timeoutError preserves the historical "i/o timeout" error while matching
    +// both context.DeadlineExceeded and os.ErrDeadlineExceeded through errors.Is.
    +// This mirrors the behavior of net.errTimeout:
    +// https://github.com/golang/go/blob/go1.27.1/src/net/net.go
    +//
    +// TODO: consider replacing ErrTimeout with os.ErrDeadlineExceeded if os.ErrDeadlineExceeded is changed to match context.DeadlineExceeded.
     type timeoutError struct{}
     
    -func (*timeoutError) Error() string   { return "i/o timeout" }
    -func (*timeoutError) Timeout() bool   { return true }
    -func (*timeoutError) Temporary() bool { return true }
    +func (e *timeoutError) Error() string   { return "i/o timeout" }
    +func (e *timeoutError) Timeout() bool   { return true }
    +func (e *timeoutError) Temporary() bool { return true }
    +func (*timeoutError) Unwrap() error     { return os.ErrDeadlineExceeded }
    +
    +func (e *timeoutError) Is(err error) bool {
    +	return err == context.DeadlineExceeded
    +}

    Let me add a small unit-test for this, to assert we're matching the various sentinel errors.

    thaJeztah thaJeztah commented on code on Oct 01, 2026 10:01 UTC
    Code Review
    file.go:1
    @@ -20,16 +21,33 @@ import (
     //sys setFileCompletionNotificationModes(h windows.Handle, flags uint8) (err error) = SetFileCompletionNotificationModes
     //sys wsaGetOverlappedResult(h windows.Handle, o *windows.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) = ws2_32.WSAGetOverlappedResult
     
    -var (
    -	ErrFileClosed = errors.New("file has already been closed")
    -	ErrTimeout    = &timeoutError{}
    -)
    -
    +// ErrFileClosed is returned when an operation is performed on a closed file.
    +//
    +// Deprecated: use [os.ErrClosed] instead.
    +var ErrFileClosed = os.ErrClosed
    +
    +// ErrTimeout is returned when an I/O operation exceeds its deadline.
    +//
    +// It matches both [context.DeadlineExceeded] and [os.ErrDeadlineExceeded]
    +// with [errors.Is].
    +var ErrTimeout error = &timeoutError{}
    +
    +// timeoutError preserves the historical "i/o timeout" error while matching
    +// both context.DeadlineExceeded and os.ErrDeadlineExceeded through errors.Is.
    +// This mirrors the behavior of net.errTimeout:
    +// https://github.com/golang/go/blob/go1.27.1/src/net/net.go
    +//
    +// TODO: consider replacing ErrTimeout with os.ErrDeadlineExceeded if os.ErrDeadlineExceeded is changed to match context.DeadlineExceeded.
     type timeoutError struct{}
     
    -func (*timeoutError) Error() string   { return "i/o timeout" }
    -func (*timeoutError) Timeout() bool   { return true }
    -func (*timeoutError) Temporary() bool { return true }
    +func (e *timeoutError) Error() string   { return "i/o timeout" }
    +func (e *timeoutError) Timeout() bool   { return true }
    +func (e *timeoutError) Temporary() bool { return true }
    +func (*timeoutError) Unwrap() error     { return os.ErrDeadlineExceeded }
    +
    +func (e *timeoutError) Is(err error) bool {
    +	return err == context.DeadlineExceeded
    +}

    👍 done 😅

    jterry75 jterry75 approved these changes on Oct 01, 2026 18:02 UTC
    Approved Reviewer

    Approved these changes.

    thaJeztah thaJeztah commented on Oct 01, 2026 20:10 UTC
    Author

    Derp: of course linter has something to say 🤣

    I'll have a look at making it happy when I get back to my computer

    thaJeztah thaJeztah commented on Oct 01, 2026 21:53 UTC
    Author

    @jterry75 fixed the linting issues (helps to run golangci-lint with GOOS=windows 😂 )

    jterry75 jterry75 approved these changes on Oct 05, 2026 17:18 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    thaJeztah thaJeztah
    Labels
    risk: low confidence: 80.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39% (MEDIUM) · Higher = larger blast radius
    39%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 80.1% · Lower = rushed or shallow review
    80.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.8% · Safe to merge
    7.8%