mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user