From 60185c5eb39da0443c642f7d021f04a5db734405 Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Thu, 29 Jun 2017 15:02:46 -0700 Subject: [PATCH] container: Handle failed memdb lookups If a container doesn't exist in the memdb, First will return nil, not an error. This should be checked for before using the result. Signed-off-by: Aaron Lehmann Upstream-commit: c26b0cdfd1a026af88fcfbed9d3c3acdd6d171a0 Component: engine --- components/engine/container/view.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/engine/container/view.go b/components/engine/container/view.go index 13c7161852..f605b4f483 100644 --- a/components/engine/container/view.go +++ b/components/engine/container/view.go @@ -73,6 +73,17 @@ type memDB struct { store *memdb.MemDB } +// NoSuchContainerError indicates that the container wasn't found in the +// database. +type NoSuchContainerError struct { + id string +} + +// Error satisfies the error interface. +func (e NoSuchContainerError) Error() string { + return "no such container " + e.id +} + // NewViewDB provides the default implementation, with the default schema func NewViewDB() (ViewDB, error) { store, err := memdb.NewMemDB(schema) @@ -134,6 +145,9 @@ func (v *memdbView) Get(id string) (*Snapshot, error) { if err != nil { return nil, err } + if s == nil { + return nil, NoSuchContainerError{id: id} + } return v.transform(s.(*Container)), nil }