github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/cd-service/pkg/repository/error.go (about)

     1  /*This file is part of kuberpult.
     2  
     3  Kuberpult is free software: you can redistribute it and/or modify
     4  it under the terms of the Expat(MIT) License as published by
     5  the Free Software Foundation.
     6  
     7  Kuberpult is distributed in the hope that it will be useful,
     8  but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10  MIT License for more details.
    11  
    12  You should have received a copy of the MIT License
    13  along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
    14  
    15  Copyright 2023 freiheit.com*/
    16  
    17  package repository
    18  
    19  import (
    20  	api "github.com/freiheit-com/kuberpult/pkg/api/v1"
    21  	"google.golang.org/protobuf/proto"
    22  )
    23  
    24  type CreateReleaseError struct {
    25  	response api.CreateReleaseResponse
    26  }
    27  
    28  func (e *CreateReleaseError) Error() string {
    29  	return e.response.String()
    30  }
    31  
    32  func (e *CreateReleaseError) Response() *api.CreateReleaseResponse {
    33  	if e == nil {
    34  		return nil
    35  	}
    36  	return &e.response
    37  }
    38  
    39  func (e *CreateReleaseError) Is(target error) bool {
    40  	tgt, ok := target.(*CreateReleaseError)
    41  	if !ok {
    42  		return false
    43  	}
    44  	return proto.Equal(e.Response(), tgt.Response())
    45  }
    46  
    47  func GetCreateReleaseGeneralFailure(err error) *CreateReleaseError {
    48  	response := api.CreateReleaseResponseGeneralFailure{
    49  		Message: err.Error(),
    50  	}
    51  	return &CreateReleaseError{
    52  		response: api.CreateReleaseResponse{
    53  			Response: &api.CreateReleaseResponse_GeneralFailure{
    54  				GeneralFailure: &response,
    55  			},
    56  		},
    57  	}
    58  }
    59  
    60  func GetCreateReleaseAlreadyExistsSame() *CreateReleaseError {
    61  	response := api.CreateReleaseResponseAlreadyExistsSame{}
    62  	return &CreateReleaseError{
    63  		response: api.CreateReleaseResponse{
    64  			Response: &api.CreateReleaseResponse_AlreadyExistsSame{
    65  				AlreadyExistsSame: &response,
    66  			},
    67  		},
    68  	}
    69  }
    70  
    71  func GetCreateReleaseAlreadyExistsDifferent(firstDifferingField api.DifferingField, diff string) *CreateReleaseError {
    72  	response := api.CreateReleaseResponseAlreadyExistsDifferent{
    73  		FirstDifferingField: firstDifferingField,
    74  		Diff:                diff,
    75  	}
    76  	return &CreateReleaseError{
    77  		response: api.CreateReleaseResponse{
    78  			Response: &api.CreateReleaseResponse_AlreadyExistsDifferent{
    79  				AlreadyExistsDifferent: &response,
    80  			},
    81  		},
    82  	}
    83  }
    84  
    85  func GetCreateReleaseTooOld() *CreateReleaseError {
    86  	response := api.CreateReleaseResponseTooOld{}
    87  	return &CreateReleaseError{
    88  		response: api.CreateReleaseResponse{
    89  			Response: &api.CreateReleaseResponse_TooOld{
    90  				TooOld: &response,
    91  			},
    92  		},
    93  	}
    94  }
    95  
    96  func GetCreateReleaseAppNameTooLong(appName string, regExp string, maxLen uint32) *CreateReleaseError {
    97  	response := api.CreateReleaseResponseAppNameTooLong{
    98  		AppName: appName,
    99  		RegExp:  regExp,
   100  		MaxLen:  maxLen,
   101  	}
   102  	return &CreateReleaseError{
   103  		response: api.CreateReleaseResponse{
   104  			Response: &api.CreateReleaseResponse_TooLong{
   105  				TooLong: &response,
   106  			},
   107  		},
   108  	}
   109  }
   110  
   111  type LockedError struct {
   112  	EnvironmentApplicationLocks map[string]Lock
   113  	EnvironmentLocks            map[string]Lock
   114  }
   115  
   116  func (l *LockedError) String() string {
   117  	return "locked"
   118  }
   119  
   120  func (l *LockedError) Error() string {
   121  	return l.String()
   122  }
   123  
   124  var _ error = (*LockedError)(nil)