⚠️ 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
type ErrorType intEnumerates the categories of errors that can occur during CPE operations.
Constants
| Constant | Type | Value | Description |
|---|---|---|---|
ErrorTypeParsingFailed | ErrorType | 0 (iota) | CPE string parsing failed |
ErrorTypeInvalidFormat | ErrorType | 1 | CPE format is invalid |
ErrorTypeInvalidPart | ErrorType | 2 | CPE part value is invalid |
ErrorTypeInvalidAttribute | ErrorType | 3 | CPE attribute value is invalid |
ErrorTypeNotFound | ErrorType | 4 | Requested resource or object not found |
ErrorTypeOperationFailed | ErrorType | 5 | A CPE-related operation failed |
_ = cpeskills.ErrorTypeParsingFailed
_ = cpeskills.ErrorTypeInvalidFormat
_ = cpeskills.ErrorTypeInvalidPart
_ = cpeskills.ErrorTypeInvalidAttribute
_ = cpeskills.ErrorTypeNotFound
_ = cpeskills.ErrorTypeOperationFailedType: CPEError
type CPEError struct {
Type ErrorType
Message string
CPEString string
Err error
}The unified error struct for all CPE operations.
| Field | Type | Description |
|---|---|---|
Type | ErrorType | The error category |
Message | string | Human-readable error description |
CPEString | string | The CPE string related to the error |
Err | error | The underlying original error, if any |
📝 Error
func (e *CPEError) Error() stringImplements the standard error interface. If CPEString is set, the message includes it as Message: CPEString.
| Return | Type | Description |
|---|---|---|
| #1 | string | The formatted error message |
err := cpeskills.NewInvalidFormatError("cpe:2.3:INVALID FORMAT")
fmt.Println(err.Error()) // invalid CPE format: cpe:2.3:INVALID FORMAT🔗 Unwrap
func (e *CPEError) Unwrap() errorReturns the wrapped underlying error, enabling errors.Is and errors.As (Go 1.13+ error chains).
| Return | Type | Description |
|---|---|---|
| #1 | error | The original error, or nil if none |
if cpeErr, ok := err.(*cpeskills.CPEError); ok {
if inner := cpeErr.Unwrap(); inner != nil {
log.Println("caused by:", inner)
}
}🆕 NewParsingError
func NewParsingError(cpeString string, err error) *CPEErrorCreates an error representing a CPE string parsing failure.
| Parameter | Type | Description |
|---|---|---|
cpeString | string | The CPE string that could not be parsed |
err | error | The underlying error that caused parsing to fail |
| Return | Type | Description |
|---|---|---|
| #1 | *CPEError | A CPEError with Type == ErrorTypeParsingFailed |
return cpeskills.NewParsingError(cpeStr, err)🚫 NewInvalidFormatError
func NewInvalidFormatError(cpeString string) *CPEErrorCreates an error indicating the CPE format is invalid.
| Parameter | Type | Description |
|---|---|---|
cpeString | string | The CPE string with invalid format |
| Return | Type | Description |
|---|---|---|
| #1 | *CPEError | A CPEError with Type == ErrorTypeInvalidFormat |
return cpeskills.NewInvalidFormatError(cpeStr)🧩 NewInvalidPartError
func NewInvalidPartError(part string) *CPEErrorCreates an error indicating an invalid CPE part value.
| Parameter | Type | Description |
|---|---|---|
part | string | The invalid part value |
| Return | Type | Description |
|---|---|---|
| #1 | *CPEError | A CPEError with Type == ErrorTypeInvalidPart |
return cpeskills.NewInvalidPartError(part)🏷️ NewInvalidAttributeError
func NewInvalidAttributeError(attribute, value string) *CPEErrorCreates an error indicating an invalid CPE attribute value.
| Parameter | Type | Description |
|---|---|---|
attribute | string | The attribute name |
value | string | The invalid attribute value |
| Return | Type | Description |
|---|---|---|
| #1 | *CPEError | A CPEError with Type == ErrorTypeInvalidAttribute |
return cpeskills.NewInvalidAttributeError("product", product)🔍 NewNotFoundError
func NewNotFoundError(what string) *CPEErrorCreates an error indicating a resource was not found.
| Parameter | Type | Description |
|---|---|---|
what | string | Description of the resource that was not found |
| Return | Type | Description |
|---|---|---|
| #1 | *CPEError | A CPEError with Type == ErrorTypeNotFound |
return cpeskills.NewNotFoundError(fmt.Sprintf("CPE with ID %s", cpeID))⚙️ NewOperationFailedError
func NewOperationFailedError(operation string, err error) *CPEErrorCreates an error indicating an operation failed.
| Parameter | Type | Description |
|---|---|---|
operation | string | Description of the failed operation |
err | error | The underlying error that caused the failure |
| Return | Type | Description |
|---|---|---|
| #1 | *CPEError | A CPEError with Type == ErrorTypeOperationFailed |
return cpeskills.NewOperationFailedError("save CPE to storage", err)❓ IsParsingError
func IsParsingError(err error) boolReturns true if err is a *CPEError with Type == ErrorTypeParsingFailed.
| Parameter | Type | Description |
|---|---|---|
err | error | The error to check |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is a parsing error |
if cpeskills.IsParsingError(err) {
log.Printf("parsing error: %v", err)
}❓ IsInvalidFormatError
func IsInvalidFormatError(err error) boolReturns true if err is a *CPEError with Type == ErrorTypeInvalidFormat.
| Parameter | Type | Description |
|---|---|---|
err | error | The error to check |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is an invalid-format error |
if cpeskills.IsInvalidFormatError(err) { /* ... */ }❓ IsInvalidPartError
func IsInvalidPartError(err error) boolReturns true if err is a *CPEError with Type == ErrorTypeInvalidPart.
| Parameter | Type | Description |
|---|---|---|
err | error | The error to check |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is an invalid-part error |
if cpeskills.IsInvalidPartError(err) { /* ... */ }❓ IsInvalidAttributeError
func IsInvalidAttributeError(err error) boolReturns true if err is a *CPEError with Type == ErrorTypeInvalidAttribute.
| Parameter | Type | Description |
|---|---|---|
err | error | The error to check |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is an invalid-attribute error |
if cpeskills.IsInvalidAttributeError(err) { /* ... */ }❓ IsNotFoundError
func IsNotFoundError(err error) boolReturns true if err is a *CPEError with Type == ErrorTypeNotFound.
| Parameter | Type | Description |
|---|---|---|
err | error | The error to check |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is a not-found error |
if cpeskills.IsNotFoundError(err) { /* ... */ }❓ IsOperationFailedError
func IsOperationFailedError(err error) boolReturns true if err is a *CPEError with Type == ErrorTypeOperationFailed.
| Parameter | Type | Description |
|---|---|---|
err | error | The error to check |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is an operation-failed error |
if cpeskills.IsOperationFailedError(err) { /* ... */ }