Skip to content

⚠️ Error Types

The cpeskills package exposes a unified error type CPEError plus a set of typed constructors and predicate helpers so callers can branch on the specific failure category.

Type: ErrorType

go
type ErrorType int

Enumerates the categories of errors that can occur during CPE operations.

Constants

ConstantTypeValueDescription
ErrorTypeParsingFailedErrorType0 (iota)CPE string parsing failed
ErrorTypeInvalidFormatErrorType1CPE format is invalid
ErrorTypeInvalidPartErrorType2CPE part value is invalid
ErrorTypeInvalidAttributeErrorType3CPE attribute value is invalid
ErrorTypeNotFoundErrorType4Requested resource or object not found
ErrorTypeOperationFailedErrorType5A CPE-related operation failed
go
_ = cpeskills.ErrorTypeParsingFailed
_ = cpeskills.ErrorTypeInvalidFormat
_ = cpeskills.ErrorTypeInvalidPart
_ = cpeskills.ErrorTypeInvalidAttribute
_ = cpeskills.ErrorTypeNotFound
_ = cpeskills.ErrorTypeOperationFailed

Type: CPEError

go
type CPEError struct {
    Type      ErrorType
    Message   string
    CPEString string
    Err       error
}

The unified error struct for all CPE operations.

FieldTypeDescription
TypeErrorTypeThe error category
MessagestringHuman-readable error description
CPEStringstringThe CPE string related to the error
ErrerrorThe underlying original error, if any

📝 Error

go
func (e *CPEError) Error() string

Implements the standard error interface. If CPEString is set, the message includes it as Message: CPEString.

ReturnTypeDescription
#1stringThe formatted error message
go
err := cpeskills.NewInvalidFormatError("cpe:2.3:INVALID FORMAT")
fmt.Println(err.Error()) // invalid CPE format: cpe:2.3:INVALID FORMAT

🔗 Unwrap

go
func (e *CPEError) Unwrap() error

Returns the wrapped underlying error, enabling errors.Is and errors.As (Go 1.13+ error chains).

ReturnTypeDescription
#1errorThe original error, or nil if none
go
if cpeErr, ok := err.(*cpeskills.CPEError); ok {
    if inner := cpeErr.Unwrap(); inner != nil {
        log.Println("caused by:", inner)
    }
}

🆕 NewParsingError

go
func NewParsingError(cpeString string, err error) *CPEError

Creates an error representing a CPE string parsing failure.

ParameterTypeDescription
cpeStringstringThe CPE string that could not be parsed
errerrorThe underlying error that caused parsing to fail
ReturnTypeDescription
#1*CPEErrorA CPEError with Type == ErrorTypeParsingFailed
go
return cpeskills.NewParsingError(cpeStr, err)

🚫 NewInvalidFormatError

go
func NewInvalidFormatError(cpeString string) *CPEError

Creates an error indicating the CPE format is invalid.

ParameterTypeDescription
cpeStringstringThe CPE string with invalid format
ReturnTypeDescription
#1*CPEErrorA CPEError with Type == ErrorTypeInvalidFormat
go
return cpeskills.NewInvalidFormatError(cpeStr)

🧩 NewInvalidPartError

go
func NewInvalidPartError(part string) *CPEError

Creates an error indicating an invalid CPE part value.

ParameterTypeDescription
partstringThe invalid part value
ReturnTypeDescription
#1*CPEErrorA CPEError with Type == ErrorTypeInvalidPart
go
return cpeskills.NewInvalidPartError(part)

🏷️ NewInvalidAttributeError

go
func NewInvalidAttributeError(attribute, value string) *CPEError

Creates an error indicating an invalid CPE attribute value.

ParameterTypeDescription
attributestringThe attribute name
valuestringThe invalid attribute value
ReturnTypeDescription
#1*CPEErrorA CPEError with Type == ErrorTypeInvalidAttribute
go
return cpeskills.NewInvalidAttributeError("product", product)

🔍 NewNotFoundError

go
func NewNotFoundError(what string) *CPEError

Creates an error indicating a resource was not found.

ParameterTypeDescription
whatstringDescription of the resource that was not found
ReturnTypeDescription
#1*CPEErrorA CPEError with Type == ErrorTypeNotFound
go
return cpeskills.NewNotFoundError(fmt.Sprintf("CPE with ID %s", cpeID))

⚙️ NewOperationFailedError

go
func NewOperationFailedError(operation string, err error) *CPEError

Creates an error indicating an operation failed.

ParameterTypeDescription
operationstringDescription of the failed operation
errerrorThe underlying error that caused the failure
ReturnTypeDescription
#1*CPEErrorA CPEError with Type == ErrorTypeOperationFailed
go
return cpeskills.NewOperationFailedError("save CPE to storage", err)

❓ IsParsingError

go
func IsParsingError(err error) bool

Returns true if err is a *CPEError with Type == ErrorTypeParsingFailed.

ParameterTypeDescription
errerrorThe error to check
ReturnTypeDescription
#1booltrue if it is a parsing error
go
if cpeskills.IsParsingError(err) {
    log.Printf("parsing error: %v", err)
}

❓ IsInvalidFormatError

go
func IsInvalidFormatError(err error) bool

Returns true if err is a *CPEError with Type == ErrorTypeInvalidFormat.

ParameterTypeDescription
errerrorThe error to check
ReturnTypeDescription
#1booltrue if it is an invalid-format error
go
if cpeskills.IsInvalidFormatError(err) { /* ... */ }

❓ IsInvalidPartError

go
func IsInvalidPartError(err error) bool

Returns true if err is a *CPEError with Type == ErrorTypeInvalidPart.

ParameterTypeDescription
errerrorThe error to check
ReturnTypeDescription
#1booltrue if it is an invalid-part error
go
if cpeskills.IsInvalidPartError(err) { /* ... */ }

❓ IsInvalidAttributeError

go
func IsInvalidAttributeError(err error) bool

Returns true if err is a *CPEError with Type == ErrorTypeInvalidAttribute.

ParameterTypeDescription
errerrorThe error to check
ReturnTypeDescription
#1booltrue if it is an invalid-attribute error
go
if cpeskills.IsInvalidAttributeError(err) { /* ... */ }

❓ IsNotFoundError

go
func IsNotFoundError(err error) bool

Returns true if err is a *CPEError with Type == ErrorTypeNotFound.

ParameterTypeDescription
errerrorThe error to check
ReturnTypeDescription
#1booltrue if it is a not-found error
go
if cpeskills.IsNotFoundError(err) { /* ... */ }

❓ IsOperationFailedError

go
func IsOperationFailedError(err error) bool

Returns true if err is a *CPEError with Type == ErrorTypeOperationFailed.

ParameterTypeDescription
errerrorThe error to check
ReturnTypeDescription
#1booltrue if it is an operation-failed error
go
if cpeskills.IsOperationFailedError(err) { /* ... */ }

🧭 Error Handling Flow

Released under the MIT License.