"Fossies" - the Fresh Open Source Software Archive

Member "cri-o-1.25.1/vendor/github.com/onsi/ginkgo/v2/ginkgo/command/abort.go" (7 Oct 2022, 1115 Bytes) of package /linux/misc/cri-o-1.25.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package command
    2 
    3 import "fmt"
    4 
    5 type AbortDetails struct {
    6     ExitCode  int
    7     Error     error
    8     EmitUsage bool
    9 }
   10 
   11 func Abort(details AbortDetails) {
   12     panic(details)
   13 }
   14 
   15 func AbortGracefullyWith(format string, args ...interface{}) {
   16     Abort(AbortDetails{
   17         ExitCode:  0,
   18         Error:     fmt.Errorf(format, args...),
   19         EmitUsage: false,
   20     })
   21 }
   22 
   23 func AbortWith(format string, args ...interface{}) {
   24     Abort(AbortDetails{
   25         ExitCode:  1,
   26         Error:     fmt.Errorf(format, args...),
   27         EmitUsage: false,
   28     })
   29 }
   30 
   31 func AbortWithUsage(format string, args ...interface{}) {
   32     Abort(AbortDetails{
   33         ExitCode:  1,
   34         Error:     fmt.Errorf(format, args...),
   35         EmitUsage: true,
   36     })
   37 }
   38 
   39 func AbortIfError(preamble string, err error) {
   40     if err != nil {
   41         Abort(AbortDetails{
   42             ExitCode:  1,
   43             Error:     fmt.Errorf("%s\n%s", preamble, err.Error()),
   44             EmitUsage: false,
   45         })
   46     }
   47 }
   48 
   49 func AbortIfErrors(preamble string, errors []error) {
   50     if len(errors) > 0 {
   51         out := ""
   52         for _, err := range errors {
   53             out += err.Error()
   54         }
   55         Abort(AbortDetails{
   56             ExitCode:  1,
   57             Error:     fmt.Errorf("%s\n%s", preamble, out),
   58             EmitUsage: false,
   59         })
   60     }
   61 }