Skip to content

Commit ae10022

Browse files
committed
pkg: truncindex: provide more info in error
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
1 parent 8bbe3de commit ae10022

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/truncindex/truncindex.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ var (
1616
// ErrEmptyPrefix is an error returned if the prefix was empty.
1717
ErrEmptyPrefix = errors.New("Prefix can't be empty")
1818

19-
// ErrAmbiguousPrefix is returned if the prefix was ambiguous
20-
// (multiple ids for the prefix).
21-
ErrAmbiguousPrefix = errors.New("Multiple IDs found with provided prefix")
22-
2319
// ErrIllegalChar is returned when a space is in the ID
2420
ErrIllegalChar = errors.New("illegal character: ' '")
2521

2622
// ErrNotExist is returned when ID or its prefix not found in index.
2723
ErrNotExist = errors.New("ID does not exist")
2824
)
2925

26+
// ErrAmbiguousPrefix is returned if the prefix was ambiguous
27+
// (multiple ids for the prefix).
28+
type ErrAmbiguousPrefix struct {
29+
prefix string
30+
}
31+
32+
func (e ErrAmbiguousPrefix) Error() string {
33+
return fmt.Sprintf("Multiple IDs found with provided prefix: %s", e.prefix)
34+
}
35+
3036
// TruncIndex allows the retrieval of string identifiers by any of their unique prefixes.
3137
// This is used to retrieve image and container IDs by more convenient shorthand prefixes.
3238
type TruncIndex struct {
@@ -105,7 +111,7 @@ func (idx *TruncIndex) Get(s string) (string, error) {
105111
if id != "" {
106112
// we haven't found the ID if there are two or more IDs
107113
id = ""
108-
return ErrAmbiguousPrefix
114+
return ErrAmbiguousPrefix{prefix: string(prefix)}
109115
}
110116
id = string(prefix)
111117
return nil

0 commit comments

Comments
 (0)