mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Merge pull request #21292 from runcom/pkg-error-truncindex
pkg: truncindex: provide more info in error
This commit is contained in:
		
						commit
						d3afe34b51
					
				
					 1 changed files with 11 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -16,10 +16,6 @@ var (
 | 
			
		|||
	// ErrEmptyPrefix is an error returned if the prefix was empty.
 | 
			
		||||
	ErrEmptyPrefix = errors.New("Prefix can't be empty")
 | 
			
		||||
 | 
			
		||||
	// ErrAmbiguousPrefix is returned if the prefix was ambiguous
 | 
			
		||||
	// (multiple ids for the prefix).
 | 
			
		||||
	ErrAmbiguousPrefix = errors.New("Multiple IDs found with provided prefix")
 | 
			
		||||
 | 
			
		||||
	// ErrIllegalChar is returned when a space is in the ID
 | 
			
		||||
	ErrIllegalChar = errors.New("illegal character: ' '")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +23,16 @@ var (
 | 
			
		|||
	ErrNotExist = errors.New("ID does not exist")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ErrAmbiguousPrefix is returned if the prefix was ambiguous
 | 
			
		||||
// (multiple ids for the prefix).
 | 
			
		||||
type ErrAmbiguousPrefix struct {
 | 
			
		||||
	prefix string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e ErrAmbiguousPrefix) Error() string {
 | 
			
		||||
	return fmt.Sprintf("Multiple IDs found with provided prefix: %s", e.prefix)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TruncIndex allows the retrieval of string identifiers by any of their unique prefixes.
 | 
			
		||||
// This is used to retrieve image and container IDs by more convenient shorthand prefixes.
 | 
			
		||||
type TruncIndex struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -105,7 +111,7 @@ func (idx *TruncIndex) Get(s string) (string, error) {
 | 
			
		|||
		if id != "" {
 | 
			
		||||
			// we haven't found the ID if there are two or more IDs
 | 
			
		||||
			id = ""
 | 
			
		||||
			return ErrAmbiguousPrefix
 | 
			
		||||
			return ErrAmbiguousPrefix{prefix: string(prefix)}
 | 
			
		||||
		}
 | 
			
		||||
		id = string(prefix)
 | 
			
		||||
		return nil
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue