Do not rely on string comparison in truncindex

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-11-03 17:19:18 -08:00
parent 9f0f24ea63
commit ac6d5a4f39

View file

@ -22,6 +22,9 @@ var (
// ErrIllegalChar is returned when a space is in the ID
ErrIllegalChar = errors.New("illegal character: ' '")
// ErrNotExist is returned when ID or its prefix not found in index.
ErrNotExist = errors.New("ID does not exist")
)
// TruncIndex allows the retrieval of string identifiers by any of their unique prefixes.
@ -116,7 +119,7 @@ func (idx *TruncIndex) Get(s string) (string, error) {
if id != "" {
return id, nil
}
return "", fmt.Errorf("no such id: %s", s)
return "", ErrNotExist
}
// Iterate iterates over all stored IDs, and passes each of them to the given handler.