返回 DeepSeek-Reasonix
recovery_wait.go
根目录 / internal / provider / recovery_wait.go
1 package provider
2
3 import (
4 "errors"
5 "fmt"
6 "time"
7 )
8
9 // RecoveryWaitExhaustedError ends managed waiting once the total wait budget
10 // is spent, so a turn on an unreachable provider fails instead of hanging.
11 type RecoveryWaitExhaustedError struct {
12 Phase string
13 Code string
14 Status int
15 Waited time.Duration
16 Attempts int
17 Cause error
18 }
19
20 func (e *RecoveryWaitExhaustedError) Error() string {
21 msg := fmt.Sprintf("provider unreachable for %s (%s)", e.Waited.Round(time.Second), e.Phase)
22 if e.Cause != nil {
23 return msg + ": " + e.Cause.Error()
24 }
25 return msg
26 }
27
28 func (e *RecoveryWaitExhaustedError) Unwrap() error { return e.Cause }
29
30 func AsRecoveryWaitExhausted(err error) *RecoveryWaitExhaustedError {
31 var exhausted *RecoveryWaitExhaustedError
32 if errors.As(err, &exhausted) {
33 return exhausted
34 }
35 return nil
36 }
37
37 lines GO