소스 검색

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 <aaron.lehmann@docker.com>
Aaron Lehmann 8 년 전
부모
커밋
c26b0cdfd1
1개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      container/view.go

+ 14 - 0
container/view.go

@@ -73,6 +73,17 @@ type memDB struct {
 	store *memdb.MemDB
 	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
 // NewViewDB provides the default implementation, with the default schema
 func NewViewDB() (ViewDB, error) {
 func NewViewDB() (ViewDB, error) {
 	store, err := memdb.NewMemDB(schema)
 	store, err := memdb.NewMemDB(schema)
@@ -134,6 +145,9 @@ func (v *memdbView) Get(id string) (*Snapshot, error) {
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
+	if s == nil {
+		return nil, NoSuchContainerError{id: id}
+	}
 	return v.transform(s.(*Container)), nil
 	return v.transform(s.(*Container)), nil
 }
 }