From ac6d5a4f39d3a65fdd24c6eb33642b7fc0438e05 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 3 Nov 2015 17:19:18 -0800 Subject: [PATCH] Do not rely on string comparison in truncindex Signed-off-by: Alexander Morozov --- truncindex/truncindex.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/truncindex/truncindex.go b/truncindex/truncindex.go index 9c08c90..3037e97 100644 --- a/truncindex/truncindex.go +++ b/truncindex/truncindex.go @@ -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.