From aee93cdd9d39165eed53f64dbd0f389125cb4bbb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 13 May 2023 09:10:01 +0000 Subject: [PATCH] fix: snapshot commands panic if snapshot don't exists (backport #16138) (#16140) Co-authored-by: yihuang Co-authored-by: marbar3778 Co-authored-by: Julien Robert --- .gitignore | 6 +----- client/snapshot/dump.go | 5 +++++ store/snapshots/manager.go | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index beb476a1b631..2093d4e7e97e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,11 +24,7 @@ dist tools-stamp buf-stamp artifacts -simapp/simd/simd - -# Go -go.work -go.work.sum +tools/ # Data - ideally these don't exist baseapp/data/* diff --git a/client/snapshot/dump.go b/client/snapshot/dump.go index 917dca071512..72dadbc57254 100644 --- a/client/snapshot/dump.go +++ b/client/snapshot/dump.go @@ -3,6 +3,7 @@ package snapshot import ( "archive/tar" "compress/gzip" + "errors" "fmt" "io" "os" @@ -48,6 +49,10 @@ func DumpArchiveCmd() *cobra.Command { return err } + if snapshot == nil { + return errors.New("snapshot doesn't exist") + } + bz, err := snapshot.Marshal() if err != nil { return err diff --git a/store/snapshots/manager.go b/store/snapshots/manager.go index cc704742f912..717a74ae73fc 100644 --- a/store/snapshots/manager.go +++ b/store/snapshots/manager.go @@ -492,6 +492,10 @@ func (m *Manager) RestoreLocalSnapshot(height uint64, format uint32) error { return err } + if snapshot == nil { + return fmt.Errorf("snapshot doesn't exist, height: %d, format: %d", height, format) + } + m.mtx.Lock() defer m.mtx.Unlock()