2022-07-18 16:36:51 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2022-09-22 16:50:05 +00:00
|
|
|
"errors"
|
|
|
|
"reflect"
|
|
|
|
|
2022-07-18 16:36:51 +00:00
|
|
|
"github.com/filecoin-project/go-jsonrpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
EOutOfGas = iota + jsonrpc.FirstUserCode
|
|
|
|
EActorNotFound
|
|
|
|
)
|
|
|
|
|
|
|
|
type ErrOutOfGas struct{}
|
|
|
|
|
2022-09-21 16:28:11 +00:00
|
|
|
func (e *ErrOutOfGas) Error() string {
|
2022-07-18 16:36:51 +00:00
|
|
|
return "call ran out of gas"
|
|
|
|
}
|
|
|
|
|
|
|
|
type ErrActorNotFound struct{}
|
|
|
|
|
2022-09-21 16:28:11 +00:00
|
|
|
func (e *ErrActorNotFound) Error() string {
|
2022-07-18 16:36:51 +00:00
|
|
|
return "actor not found"
|
|
|
|
}
|
|
|
|
|
|
|
|
var RPCErrors = jsonrpc.NewErrors()
|
|
|
|
|
2022-09-22 16:50:05 +00:00
|
|
|
func ErrorIsIn(err error, errorTypes []error) bool {
|
|
|
|
for _, etype := range errorTypes {
|
|
|
|
tmp := reflect.New(reflect.PointerTo(reflect.ValueOf(etype).Elem().Type())).Interface()
|
|
|
|
if errors.As(err, tmp) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-07-18 16:36:51 +00:00
|
|
|
func init() {
|
2022-09-21 16:28:11 +00:00
|
|
|
RPCErrors.Register(EOutOfGas, new(*ErrOutOfGas))
|
|
|
|
RPCErrors.Register(EActorNotFound, new(*ErrActorNotFound))
|
2022-07-18 16:36:51 +00:00
|
|
|
}
|