github.com/replicatedhq/ship@v0.55.0/pkg/util/warnings/warn.go (about)

     1  package warnings
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  // WarnShouldUseUpdate is the message printed to the user when they attempt
    10  // to use "ship init" with a present state file on disk
    11  var WarnShouldUseUpdate = warning{msg: `To build on your progress, run "ship update"`}
    12  
    13  var WarnCannotRemoveState = warning{msg: `Existing state was found that Ship cannot automatically remove. Please delete the existing state and try again.`}
    14  
    15  // WarnShouldMoveDirectory is the message printed to the user when they attempt to run ship when files like `base` or
    16  // `overlays` are already present
    17  func WarnShouldMoveDirectory(dir string) error {
    18  	return warning{msg: fmt.Sprintf(`Found existing directory %q. To avoid losing work, please move or remove %q before proceeding, or re-run with --rm-asset-dest.`, dir, dir)}
    19  }
    20  
    21  func WarnFileNotFound(filePath string) error {
    22  	return warning{msg: fmt.Sprintf(`File %q was not found.`, filePath)}
    23  }
    24  
    25  type warning struct {
    26  	msg string
    27  }
    28  
    29  func (w warning) Error() string {
    30  	return w.msg
    31  }
    32  
    33  func IsWarning(err error) bool {
    34  	cause := errors.Cause(err)
    35  	_, ok := cause.(warning)
    36  	return ok
    37  }
    38  
    39  func StripStackIfWarning(err error) error {
    40  	if IsWarning(err) {
    41  		return errors.Cause(err)
    42  	}
    43  	return err
    44  }