Skip to content

Commit

Permalink
fix: snapshot commands panic if snapshot don't exists (backport cosmo…
Browse files Browse the repository at this point in the history
…s#16138) (cosmos#16140)

Co-authored-by: yihuang <[email protected]>
Co-authored-by: marbar3778 <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
4 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 42f1adf commit aee93cd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
5 changes: 5 additions & 0 deletions client/snapshot/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package snapshot
import (
"archive/tar"
"compress/gzip"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions store/snapshots/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit aee93cd

Please sign in to comment.