fix: use %w instead of %v for error wrapping

errutil.go: Change %v to %w in ClassifySendError and ClassifyNetError so callers can use errors.Is/errors.As on the underlying HTTP/network error.

isolated_command_transport.go: Change %v to %w in Close() and Write() error paths for the same reason.
This commit is contained in:
程智超0668000959
2026-06-08 09:10:14 +08:00
parent 875cf4a2d4
commit 3f435c5e56
2 changed files with 6 additions and 6 deletions
+4 -4
View File
@@ -11,11 +11,11 @@ import (
func ClassifySendError(statusCode int, rawErr error) error {
switch {
case statusCode == http.StatusTooManyRequests:
return fmt.Errorf("%w: %v", ErrRateLimit, rawErr)
return fmt.Errorf("%w: %w", ErrRateLimit, rawErr)
case statusCode >= 500:
return fmt.Errorf("%w: %v", ErrTemporary, rawErr)
return fmt.Errorf("%w: %w", ErrTemporary, rawErr)
case statusCode >= 400:
return fmt.Errorf("%w: %v", ErrSendFailed, rawErr)
return fmt.Errorf("%w: %w", ErrSendFailed, rawErr)
default:
return rawErr
}
@@ -26,5 +26,5 @@ func ClassifyNetError(err error) error {
if err == nil {
return nil
}
return fmt.Errorf("%w: %v", ErrTemporary, err)
return fmt.Errorf("%w: %w", ErrTemporary, err)
}
+2 -2
View File
@@ -62,7 +62,7 @@ func (s *isolatedPipeRWC) Write(p []byte) (n int, err error) {
func (s *isolatedPipeRWC) Close() error {
if err := s.stdin.Close(); err != nil {
return fmt.Errorf("closing stdin: %v", err)
return fmt.Errorf("closing stdin: %w", err)
}
resChan := make(chan error, 1)
go func() {
@@ -205,7 +205,7 @@ func (c *isolatedIOConn) Write(ctx context.Context, msg jsonrpc.Message) error {
defer c.writeMu.Unlock()
data, err := jsonrpc.EncodeMessage(msg)
if err != nil {
return fmt.Errorf("marshaling message: %v", err)
return fmt.Errorf("marshaling message: %w", err)
}
data = append(data, '\n')
_, err = c.rwc.Write(data)