github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/git/errors.go (about)

     1  package git
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  // ErrNotOnAnyBranch indicates that the user is in detached HEAD state.
     9  var ErrNotOnAnyBranch = errors.New("git: not on any branch")
    10  
    11  type NotInstalled struct {
    12  	message string
    13  	err     error
    14  }
    15  
    16  func (e *NotInstalled) Error() string {
    17  	return e.message
    18  }
    19  
    20  func (e *NotInstalled) Unwrap() error {
    21  	return e.err
    22  }
    23  
    24  type GitError struct {
    25  	ExitCode int
    26  	Stderr   string
    27  	err      error
    28  }
    29  
    30  func (ge *GitError) Error() string {
    31  	if ge.Stderr == "" {
    32  		return fmt.Sprintf("failed to run git: %v", ge.err)
    33  	}
    34  	return fmt.Sprintf("failed to run git: %s", ge.Stderr)
    35  }
    36  
    37  func (ge *GitError) Unwrap() error {
    38  	return ge.err
    39  }