cserrors

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cserrors provides error handling and logging utilities for CipherSwarm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetErrorHandler

func GetErrorHandler() *apierrors.Handler

GetErrorHandler returns the shared error handler, initializing it if needed. Thread-safe via sync.Once.

func GetErrorHandlerNoSend

func GetErrorHandlerNoSend() *apierrors.Handler

GetErrorHandlerNoSend returns an error handler that only logs (no server send). Used to prevent infinite recursion when error sending fails.

func LogAndSendError

func LogAndSendError(ctx context.Context, message string, err error, severity api.Severity, task *api.Task) error

LogAndSendError logs an error message with severity and sends it to the CipherSwarm API. When task is nil, the error is reported without a task context. API submission is skipped only when the APIClient has not been initialized yet. Empty or whitespace-only messages are handled by the centralised guard inside SendAgentError, so callers do not need their own empty-message check. Returns the original error for further handling. Callers control context: pass ctx for cancellable operations, or context.Background() for errors that must be delivered even during shutdown.

func SendAgentError

func SendAgentError(
	ctx context.Context,
	stdErrLine string,
	task *api.Task,
	severity api.Severity,
	opts ...ErrorOption,
)

SendAgentError sends an error message to the centralized server, including metadata and severity level. Optional ErrorOption arguments can enhance the error with classification metadata. Safe to call before API client initialization — logs locally and returns if client is nil. Empty or whitespace-only messages are silently dropped with a Warn-level log to prevent noise in server logs (see issue #140). Callers control context: pass ctx for cancellable operations, or context.Background() for errors that must be delivered even during shutdown.

Types

type ErrorOption

type ErrorOption func(*errorReportConfig)

ErrorOption configures optional error reporting behavior.

func WithClassification

func WithClassification(category string, retryable bool) ErrorOption

WithClassification adds error classification metadata (category and retryable flag) for better error handling on the server side.

func WithContext added in v0.6.2

func WithContext(metadata map[string]any) ErrorOption

WithContext adds structured context fields to the error metadata. Fields are merged into the metadata map alongside classification and platform info. Nil or empty maps are ignored.

Jump to

Keyboard shortcuts

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