Make storiface.CallError json-friendly
This commit is contained in:
parent
b8853aa4d5
commit
b242d69805
20
extern/sector-storage/storiface/worker.go
vendored
20
extern/sector-storage/storiface/worker.go
vendored
@ -2,6 +2,7 @@ package storiface
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
@ -104,22 +105,29 @@ const (
|
||||
)
|
||||
|
||||
type CallError struct {
|
||||
Code ErrorCode
|
||||
Sub error
|
||||
Code ErrorCode
|
||||
Message string
|
||||
sub error
|
||||
}
|
||||
|
||||
func (c *CallError) Error() string {
|
||||
return fmt.Sprintf("storage call error %d: %s", c.Code, c.Sub.Error())
|
||||
return fmt.Sprintf("storage call error %d: %s", c.Code, c.Message)
|
||||
}
|
||||
|
||||
func (c *CallError) Unwrap() error {
|
||||
return c.Sub
|
||||
if c.sub != nil {
|
||||
return c.sub
|
||||
}
|
||||
|
||||
return errors.New(c.Message)
|
||||
}
|
||||
|
||||
func Err(code ErrorCode, sub error) *CallError {
|
||||
return &CallError{
|
||||
Code: code,
|
||||
Sub: sub,
|
||||
Code: code,
|
||||
Message: sub.Error(),
|
||||
|
||||
sub: sub,
|
||||
}
|
||||
}
|
||||
|
||||
|
10
extern/sector-storage/worker_local.go
vendored
10
extern/sector-storage/worker_local.go
vendored
@ -90,10 +90,7 @@ func newLocalWorker(executor ExecutorFunc, wcfg WorkerConfig, store stores.Store
|
||||
|
||||
go func() {
|
||||
for _, call := range unfinished {
|
||||
err := &storiface.CallError{
|
||||
Sub: xerrors.New("worker restarted"),
|
||||
Code: storiface.ErrTempWorkerRestart,
|
||||
}
|
||||
err := storiface.Err(storiface.ErrTempWorkerRestart, xerrors.New("worker restarted"))
|
||||
|
||||
// TODO: Handle restarting PC1 once support is merged
|
||||
|
||||
@ -261,10 +258,7 @@ func (l *LocalWorker) asyncCall(ctx context.Context, sector storage.SectorRef, r
|
||||
func toCallError(err error) *storiface.CallError {
|
||||
var serr *storiface.CallError
|
||||
if err != nil && !xerrors.As(err, &serr) {
|
||||
serr = &storiface.CallError{
|
||||
Sub: err,
|
||||
Code: storiface.ErrUnknown,
|
||||
}
|
||||
serr = storiface.Err(storiface.ErrUnknown, err)
|
||||
}
|
||||
|
||||
return serr
|
||||
|
Loading…
Reference in New Issue
Block a user