github.com/grafana/tanka@v0.26.1-0.20240506093700-c22cfc35c21a/pkg/tanka/errors.go (about)

     1  package tanka
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // ErrNoEnv means that the given jsonnet has no Environment object
     9  // This must not be fatal, some operations work without
    10  type ErrNoEnv struct {
    11  	path string
    12  }
    13  
    14  func (e ErrNoEnv) Error() string {
    15  	return fmt.Sprintf("unable to find an Environment in '%s'", e.path)
    16  }
    17  
    18  // ErrMultipleEnvs means that the given jsonnet has multiple Environment objects
    19  type ErrMultipleEnvs struct {
    20  	path      string
    21  	givenName string
    22  	foundEnvs []string
    23  }
    24  
    25  func (e ErrMultipleEnvs) Error() string {
    26  	if e.givenName != "" {
    27  		return fmt.Sprintf("found multiple Environments in %q matching %q. Provide a more specific name that matches a single one: \n - %s", e.path, e.givenName, strings.Join(e.foundEnvs, "\n - "))
    28  	}
    29  
    30  	return fmt.Sprintf("found multiple Environments in %q. Use `--name` to select a single one: \n - %s", e.path, strings.Join(e.foundEnvs, "\n - "))
    31  }
    32  
    33  // ErrParallel is an array of errors collected while processing in parallel
    34  type ErrParallel struct {
    35  	errors []error
    36  }
    37  
    38  func (e ErrParallel) Error() string {
    39  	returnErr := "Errors occurred during parallel processing:\n\n"
    40  	for _, err := range e.errors {
    41  		returnErr = fmt.Sprintf("%s- %s\n\n", returnErr, err.Error())
    42  	}
    43  	return returnErr
    44  }