Files
seaweedfs/seaweed-block/cmd/sw-block/volume_answer.go
T

53 lines
1.7 KiB
Go

package main
import (
"errors"
"fmt"
"github.com/seaweedfs/seaweed-block/core/rpc/answer"
)
// A whole-job command has stable derived operation identities. Preserve its
// existing wire exit while obtaining its failure class and cure centrally.
func operatorAnswer(err error, contract answer.Contract) (answer.Policy, error) {
var presented *operatorFailure
if errors.As(err, &presented) && presented.contract == contract {
return presented.policy, err
}
observed := answer.EnsureEvidence(answer.PossiblyAdmitted, err)
if _, listed := answer.ErrorKind(observed); !listed {
// These callers have already checked a reply's identity/completeness
// or lost their workflow's observation; this is not a transport guess.
observed = answer.Rekind(observed, answer.Guard("outcome_unknown"))
}
policy, check := answer.PolicyOf(observed, contract)
if check != nil {
policy, _ = answer.Lookup(answer.Unsent, answer.Guard("internal"))
return policy, fmt.Errorf("%w; %v", err, check)
}
if policy.Code == "outcome_unknown" {
return policy, &operatorFailure{policy, contract, fmt.Errorf("the outcome is unknown (%w); %s", err, policy.Cure)}
}
return policy, &operatorFailure{policy, contract, fmt.Errorf("%s: %w; %s", policy.Code, err, policy.Cure)}
}
type operatorFailure struct {
policy answer.Policy
contract answer.Contract
err error
}
func (e *operatorFailure) Error() string { return e.err.Error() }
func (e *operatorFailure) Unwrap() error { return e.err }
func inspectionError(err error) error {
if err == nil {
return nil
}
if _, listed := answer.ErrorKind(err); !listed {
return err
} // explicit business finding, not a transport failure
_, detail := operatorAnswer(err, answer.Shell)
return detail
}