2019-07-19 15:04:47 +00:00
|
|
|
package aerrors_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/exitcode"
|
2019-10-18 04:47:41 +00:00
|
|
|
. "github.com/filecoin-project/lotus/chain/actors/aerrors"
|
2019-07-19 15:04:47 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFatalError(t *testing.T) {
|
|
|
|
e1 := xerrors.New("out of disk space")
|
|
|
|
e2 := xerrors.Errorf("could not put node: %w", e1)
|
|
|
|
e3 := xerrors.Errorf("could not save head: %w", e2)
|
|
|
|
ae := Escalate(e3, "failed to save the head")
|
|
|
|
aw1 := Wrap(ae, "saving head of new miner actor")
|
|
|
|
aw2 := Absorb(aw1, 1, "try to absorb fatal error")
|
|
|
|
aw3 := Wrap(aw2, "initializing actor")
|
|
|
|
aw4 := Wrap(aw3, "creating miner in storage market")
|
|
|
|
t.Logf("Verbose error: %+v", aw4)
|
|
|
|
t.Logf("Normal error: %v", aw4)
|
|
|
|
assert.True(t, IsFatal(aw4), "should be fatal")
|
|
|
|
}
|
|
|
|
func TestAbsorbeError(t *testing.T) {
|
|
|
|
e1 := xerrors.New("EOF")
|
|
|
|
e2 := xerrors.Errorf("could not decode: %w", e1)
|
|
|
|
ae := Absorb(e2, 35, "failed to decode CBOR")
|
|
|
|
aw1 := Wrap(ae, "saving head of new miner actor")
|
|
|
|
aw2 := Wrap(aw1, "initializing actor")
|
|
|
|
aw3 := Wrap(aw2, "creating miner in storage market")
|
|
|
|
t.Logf("Verbose error: %+v", aw3)
|
|
|
|
t.Logf("Normal error: %v", aw3)
|
2020-04-02 18:24:38 +00:00
|
|
|
assert.Equal(t, exitcode.ExitCode(35), RetCode(aw3))
|
2019-07-19 15:04:47 +00:00
|
|
|
}
|