github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/pkg/errors/exit_error.go (about)

     1  package errors
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/fastly/cli/pkg/text"
     7  )
     8  
     9  // SkipExitError is an error that can cause the os.Exit(1) to be skipped.
    10  // An example is 'help' output (e.g. --help).
    11  type SkipExitError struct {
    12  	Skip bool
    13  	Err  error
    14  }
    15  
    16  // Unwrap returns the inner error.
    17  func (ee SkipExitError) Unwrap() error {
    18  	return ee.Err
    19  }
    20  
    21  // Error prints the inner error string.
    22  func (ee SkipExitError) Error() string {
    23  	if ee.Err == nil {
    24  		return ""
    25  	}
    26  	return ee.Err.Error()
    27  }
    28  
    29  // Print the error to the io.Writer for human consumption.
    30  // The inner error is always printed via text.Output with an "Error: " prefix
    31  // and a "." suffix.
    32  func (ee SkipExitError) Print(w io.Writer) {
    33  	if ee.Err != nil {
    34  		text.Error(w, "%s.", ee.Err.Error())
    35  	}
    36  }