From f9c759fcb2be3c68f3880a01ae99b7fa6435e71a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 20 Jul 2021 11:28:27 -0700 Subject: [PATCH] fix: always check if StateSearchMessage returns nil It returns nil on "not found". Fixes the cases not covered in: https://github.com/filecoin-project/lotus/pull/6787 --- cli/state.go | 7 +++++++ cmd/tvx/extract_message.go | 3 +++ itests/api_test.go | 1 + 3 files changed, 11 insertions(+) diff --git a/cli/state.go b/cli/state.go index 5bfcf1e8f..d5251fb85 100644 --- a/cli/state.go +++ b/cli/state.go @@ -446,6 +446,9 @@ var StateExecTraceCmd = &cli.Command{ if err != nil { return err } + if lookup == nil { + return fmt.Errorf("failed to find message: %s", mcid) + } ts, err := capi.ChainGetTipSet(ctx, lookup.TipSet) if err != nil { @@ -1491,6 +1494,10 @@ var StateSearchMsgCmd = &cli.Command{ return err } + if mw == nil { + return fmt.Errorf("failed to find message: %s", msg) + } + m, err := api.ChainGetMessage(ctx, msg) if err != nil { return err diff --git a/cmd/tvx/extract_message.go b/cmd/tvx/extract_message.go index 8e993cbd3..71035867f 100644 --- a/cmd/tvx/extract_message.go +++ b/cmd/tvx/extract_message.go @@ -337,6 +337,9 @@ func resolveFromChain(ctx context.Context, api v0api.FullNode, mcid cid.Cid, blo if err != nil { return nil, nil, nil, fmt.Errorf("failed to locate message: %w", err) } + if msgInfo == nil { + return nil, nil, nil, fmt.Errorf("failed to locate message: not found") + } log.Printf("located message at tipset %s (height: %d) with exit code: %s", msgInfo.TipSet, msgInfo.Height, msgInfo.Receipt.ExitCode) diff --git a/itests/api_test.go b/itests/api_test.go index 1b60630fd..ba77701a2 100644 --- a/itests/api_test.go +++ b/itests/api_test.go @@ -121,6 +121,7 @@ func (ts *apiSuite) testSearchMsg(t *testing.T) { searchRes, err := full.StateSearchMsg(ctx, types.EmptyTSK, sm.Cid(), lapi.LookbackNoLimit, true) require.NoError(t, err) + require.NotNil(t, searchRes) require.Equalf(t, res.TipSet, searchRes.TipSet, "search ts: %s, different from wait ts: %s", searchRes.TipSet, res.TipSet) }