errorutils

package
v0.0.0-...-c3d9892 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorCode

func ErrorCode(err error) string

ErrorCode returns the top level error code if the error is a ResponseError.

func HandleCredentialError

func HandleCredentialError(ctx context.Context, invalidator environs.CredentialInvalidator, err error) (bool, error)

HandleCredentialError determines if given error relates to invalid credential. If it is, the credential is invalidated. Original error is returned untouched.

func HasDenialStatusCode

func HasDenialStatusCode(err error) bool

HasDenialStatusCode returns true of the error has a status code meaning that the credential is invalid.

func IsAuthorisationFailure

func IsAuthorisationFailure(err error) bool

IsAuthorisationFailure returns true if the error is caused by an authorisation failure.

func IsConflictError

func IsConflictError(err error) bool

IsConflictError returns true if the error is caused by a deployment Conflict.

func IsForbiddenError

func IsForbiddenError(err error) bool

IsForbiddenError returns true if the error is caused by a forbidden error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is caused by a not found error.

func MaybeHypervisorGenNotSupportedError

func MaybeHypervisorGenNotSupportedError(err error) (error, bool)

MaybeHypervisorGenNotSupportedError returns the relevant error message and true if the error is caused by a Hypervisor Generation not supported for the selected VM size. Azure does not give a specific error code for this issue, so we have to check the error message. Example error message:

&errorutils.serviceError{
    Code:    "DeploymentFailed",
    Message: "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
    Details: {
        {Code:"BadRequest", Message:"{
          "error": {
            "code": "BadRequest",
            "message": "The selected VM size 'Standard_D2_v2' cannot boot Hypervisor Generation '2'. If this was a Create operation please check that the Hypervisor Generation of the Image matches the Hypervisor Generation of the selected VM Size. If this was an Update operation please select a Hypervisor Generation '2' VM Size. For more information, see https://aka.ms/azuregen2vm"
          }
        }"},
    },
}

func MaybeQuotaExceededError

func MaybeQuotaExceededError(err error) (error, bool)

MaybeQuotaExceededError returns the relevant error message and true if the error is caused by a Quota Exceeded issue.

func SimpleError

func SimpleError(err error) error

SimpleError returns an error with the "interesting" content from a ResponseError.

func StatusCode

func StatusCode(err error) int

StatusCode returns the top level status code if the error is a ResponseError.

Types

type RequestError

type RequestError struct {
	ServiceError *ServiceError `json:"error"`
}

RequestError represents an error response from Azure.

type ServiceError

type ServiceError struct {
	Code    string               `json:"code"`
	Message string               `json:"message"`
	Details []ServiceErrorDetail `json:"details"`
}

ServiceError represents an error response from Azure.

type ServiceErrorDetail

type ServiceErrorDetail struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ServiceErrorDetail represents an error detail from Azure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL