github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/buildplanner/response/commiterror.go (about)

     1  package response
     2  
     3  import (
     4  	"github.com/ActiveState/cli/internal/errs"
     5  	"github.com/ActiveState/cli/internal/locale"
     6  	"github.com/ActiveState/cli/pkg/platform/api/buildplanner/types"
     7  	"github.com/go-openapi/strfmt"
     8  )
     9  
    10  type CommitError struct {
    11  	Type                   string
    12  	Message                string
    13  	*locale.LocalizedError // for legacy, non-user-facing error usages
    14  }
    15  
    16  func ProcessCommitError(commit *Commit, fallbackMessage string) error {
    17  	if commit.Error == nil {
    18  		return errs.New(fallbackMessage)
    19  	}
    20  
    21  	switch commit.Type {
    22  	case types.NotFoundErrorType:
    23  		return &CommitError{
    24  			commit.Type, commit.Message,
    25  			locale.NewInputError("err_buildplanner_commit_not_found", "Could not find commit, received message: {{.V0}}", commit.Message),
    26  		}
    27  	case types.ParseErrorType:
    28  		return &CommitError{
    29  			commit.Type, commit.Message,
    30  			locale.NewInputError("err_buildplanner_parse_error", "The platform failed to parse the build expression, received message: {{.V0}}. Path: {{.V1}}", commit.Message, commit.ParseError.Path),
    31  		}
    32  	case types.ValidationErrorType:
    33  		return &CommitError{
    34  			commit.Type, commit.Message,
    35  			locale.NewInputError("err_buildplanner_validation_error", "The platform encountered a validation error, received message: {{.V0}}", commit.Message),
    36  		}
    37  	case types.ForbiddenErrorType:
    38  		return &CommitError{
    39  			commit.Type, commit.Message,
    40  			locale.NewInputError("err_buildplanner_forbidden", "Operation forbidden: {{.V0}}, received message: {{.V1}}", commit.Operation, commit.Message),
    41  		}
    42  	case types.HeadOnBranchMovedErrorType:
    43  		return errs.Wrap(&CommitError{
    44  			commit.Type, commit.Error.Message,
    45  			locale.NewInputError("err_buildplanner_head_on_branch_moved"),
    46  		}, "received message: "+commit.Error.Message)
    47  	case types.NoChangeSinceLastCommitErrorType:
    48  		return errs.Wrap(&CommitError{
    49  			commit.Type, commit.Error.Message,
    50  			locale.NewInputError("err_buildplanner_no_change_since_last_commit", "No new changes to commit."),
    51  		}, commit.Error.Message)
    52  	default:
    53  		return errs.New(fallbackMessage)
    54  	}
    55  }
    56  
    57  type RevertCommitError struct {
    58  	Type    string
    59  	Message string
    60  }
    61  
    62  func (m *RevertCommitError) Error() string { return m.Message }
    63  
    64  func ProcessRevertCommitError(rcErr *revertedCommit, fallbackMessage string) error {
    65  	if rcErr.Type != "" {
    66  		return &RevertCommitError{rcErr.Type, rcErr.Message}
    67  	}
    68  	return errs.New(fallbackMessage)
    69  }
    70  
    71  type MergedCommitError struct {
    72  	Type    string
    73  	Message string
    74  }
    75  
    76  func (m *MergedCommitError) Error() string { return m.Message }
    77  
    78  func ProcessMergedCommitError(mcErr *mergedCommit, fallbackMessage string) error {
    79  	if mcErr.Type != "" {
    80  		return &MergedCommitError{mcErr.Type, mcErr.Message}
    81  	}
    82  	return errs.New(fallbackMessage)
    83  }
    84  
    85  // HeadOnBranchMovedError represents an error that occurred because the head on
    86  // a remote branch has moved.
    87  type HeadOnBranchMovedError struct {
    88  	HeadBranchID strfmt.UUID `json:"branchId"`
    89  }
    90  
    91  // NoChangeSinceLastCommitError represents an error that occurred because there
    92  // were no changes since the last commit.
    93  type NoChangeSinceLastCommitError struct {
    94  	NoChangeCommitID strfmt.UUID `json:"commitId"`
    95  }
    96  
    97  // MergeConflictError represents an error that occurred because of a merge conflict.
    98  type MergeConflictError struct {
    99  	CommonAncestorID strfmt.UUID `json:"commonAncestorId"`
   100  	ConflictPaths    []string    `json:"conflictPaths"`
   101  }
   102  
   103  // MergeError represents two different errors in the BuildPlanner's graphQL
   104  // schema with the same fields. Those errors being: FastForwardError and
   105  // NoCommonBaseFound. Inspect the Type field to determine which error it is.
   106  type MergeError struct {
   107  	TargetVCSRef strfmt.UUID `json:"targetVcsRef"`
   108  	OtherVCSRef  strfmt.UUID `json:"otherVcsRef"`
   109  }