From c1e9a85008b2a2d56ca0eb477a5ad4fa04ebe455 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Thu, 30 Apr 2015 11:53:13 +0200 Subject: [PATCH] store: define specific error for key not found. It's needed when you want to know if the key exists. --- store/store.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/store/store.go b/store/store.go index 8a9c257..a4f54dc 100644 --- a/store/store.go +++ b/store/store.go @@ -20,6 +20,7 @@ import ( "crypto/sha512" "database/sql" "encoding/json" + "errors" "fmt" "hash" "io" @@ -59,6 +60,10 @@ var diskvStores = [...]string{ "imageManifest", } +var ( + ErrKeyNotFound = errors.New("no keys found") +) + // Store encapsulates a content-addressable-storage for storing ACIs on disk. type Store struct { base string @@ -220,7 +225,7 @@ func (s Store) ResolveKey(key string) (string, error) { keyCount := len(aciInfos) if keyCount == 0 { - return "", fmt.Errorf("no keys found") + return "", ErrKeyNotFound } if keyCount != 1 { return "", fmt.Errorf("ambiguous key: %q", key)