errors

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides custom error types for the OpenCTEM SDK. It follows industry best practices (HashiCorp, AWS SDK) for error handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotConnected is returned when the client is not connected.
	ErrNotConnected = &Error{Kind: KindNetwork, Message: "not connected"}

	// ErrTimeout is returned when an operation times out.
	ErrTimeout = &Error{Kind: KindTimeout, Message: "operation timed out"}

	// ErrRateLimited is returned when rate limited.
	ErrRateLimited = &Error{Kind: KindRateLimit, Message: "rate limited"}

	// ErrInvalidConfig is returned for invalid configuration.
	ErrInvalidConfig = &Error{Kind: KindInvalidInput, Message: "invalid configuration"}

	// ErrMissingAPIKey is returned when API key is missing.
	ErrMissingAPIKey = &Error{Kind: KindAuthentication, Message: "API key is required"}

	// ErrMissingAgentID is returned when agent ID is missing.
	ErrMissingAgentID = &Error{Kind: KindInvalidInput, Message: "agent ID is required"}
)

Functions

func E

func E(args ...interface{}) error

E constructs an Error from the given arguments. Arguments can be: Kind, string (Op or Message), error.

func IsAuthenticationError

func IsAuthenticationError(err error) bool

IsAuthenticationError checks if the error is an authentication error.

func IsAuthorizationError

func IsAuthorizationError(err error) bool

IsAuthorizationError checks if the error is an authorization error.

func IsNetworkError

func IsNetworkError(err error) bool

IsNetworkError checks if the error is a network error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if the error is a not found error.

func IsRateLimitError

func IsRateLimitError(err error) bool

IsRateLimitError checks if the error is a rate limit error.

func IsRetryable

func IsRetryable(err error) bool

IsRetryable checks if the error is retryable.

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError checks if the error is a timeout error.

func New

func New(message string) error

New creates a new simple error.

func Wrap

func Wrap(err error, op string) error

Wrap wraps an error with additional context.

func WrapWithMessage

func WrapWithMessage(err error, message string) error

WrapWithMessage wraps an error with a message.

Types

type APIError

type APIError struct {
	// StatusCode is the HTTP status code
	StatusCode int `json:"status_code"`

	// Code is an API-specific error code
	Code string `json:"code"`

	// Message is the error message from the API
	Message string `json:"message"`

	// RequestID is the request ID for debugging
	RequestID string `json:"request_id,omitempty"`

	// Details contains additional error context
	Details map[string]any `json:"details,omitempty"`
}

APIError represents an error returned by the OpenCTEM API.

func IsAPIError

func IsAPIError(err error) (*APIError, bool)

IsAPIError checks if err is an APIError and returns it.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

type Error

type Error struct {
	// Kind indicates the category of error
	Kind Kind

	// Op is the operation being performed (e.g., "client.PushFindings")
	Op string

	// Message is a human-readable description
	Message string

	// Err is the underlying error
	Err error
}

Error is the base error type for all SDK errors.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports whether the error matches the target.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error.

type Kind

type Kind uint8

Kind represents the kind/category of error.

const (
	KindUnknown Kind = iota
	KindInvalidInput
	KindAuthentication
	KindAuthorization
	KindNotFound
	KindConflict
	KindRateLimit
	KindTimeout
	KindNetwork
	KindServer
	KindInternal
)

func GetKind

func GetKind(err error) Kind

GetKind returns the Kind of the error, or KindUnknown.

func (Kind) String

func (k Kind) String() string

Jump to

Keyboard shortcuts

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