github.com/vmware/govmomi@v0.51.0/find/error.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package find
     6  
     7  import "fmt"
     8  
     9  type NotFoundError struct {
    10  	kind string
    11  	path string
    12  }
    13  
    14  func (e *NotFoundError) Error() string {
    15  	return fmt.Sprintf("%s '%s' not found", e.kind, e.path)
    16  }
    17  
    18  type MultipleFoundError struct {
    19  	kind string
    20  	path string
    21  }
    22  
    23  func (e *MultipleFoundError) Error() string {
    24  	return fmt.Sprintf("path '%s' resolves to multiple %ss", e.path, e.kind)
    25  }
    26  
    27  type DefaultNotFoundError struct {
    28  	kind string
    29  }
    30  
    31  func (e *DefaultNotFoundError) Error() string {
    32  	return fmt.Sprintf("no default %s found", e.kind)
    33  }
    34  
    35  type DefaultMultipleFoundError struct {
    36  	kind string
    37  }
    38  
    39  func (e DefaultMultipleFoundError) Error() string {
    40  	return fmt.Sprintf("default %s resolves to multiple instances, please specify", e.kind)
    41  }
    42  
    43  func toDefaultError(err error) error {
    44  	switch e := err.(type) {
    45  	case *NotFoundError:
    46  		return &DefaultNotFoundError{e.kind}
    47  	case *MultipleFoundError:
    48  		return &DefaultMultipleFoundError{e.kind}
    49  	default:
    50  		return err
    51  	}
    52  }