diff --git a/CHANGELOG.md b/CHANGELOG.md index f9eda5b6fba7..0b453112c01e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -223,6 +223,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/capability) [#15030](https://github.com/cosmos/cosmos-sdk/pull/15030) Prevent `x/capability` from consuming `GasMeter` gas during `InitMemStore` * (types/coin) [#14739](https://github.com/cosmos/cosmos-sdk/pull/14739) Deprecate the method `Coin.IsEqual` in favour of `Coin.Equal`. The difference between the two methods is that the first one results in a panic when denoms are not equal. This panic lead to unexpected behavior * (x/crypto) [#15258](https://github.com/cosmos/cosmos-sdk/pull/15258) Write keyhash file with permissions 0600 instead of 0555. +* (cli) [#16138](https://github.com/cosmos/cosmos-sdk/pull/16138) Fix snapshot commands panic if snapshot don't exists. ### Deprecated diff --git a/client/snapshot/dump.go b/client/snapshot/dump.go index 917dca071512..3853bdff7094 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 don't exists") + } + bz, err := snapshot.Marshal() if err != nil { return err diff --git a/store/snapshots/manager.go b/store/snapshots/manager.go index 4401613aabf8..26b3604407d1 100644 --- a/store/snapshots/manager.go +++ b/store/snapshots/manager.go @@ -425,6 +425,10 @@ func (m *Manager) RestoreLocalSnapshot(height uint64, format uint32) error { return err } + if snapshot == nil { + return fmt.Errorf("snapshot don't exists, height: %d, format: %d", height, format) + } + m.mtx.Lock() defer m.mtx.Unlock()