errors

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errors provides error handling utilities for SRAKE. It offers consistent error wrapping, logging, and handling patterns to improve error visibility throughout the codebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IgnoreError

func IgnoreError(err error, reason string)

IgnoreError explicitly ignores an error with a reason. This documents that the error is intentionally ignored.

Example:

errors.IgnoreError(file.Close(), "cleanup during error recovery")

func IsKind

func IsKind(err error, kind Kind) bool

IsKind checks if an error is of the given kind.

func LogAndContinue

func LogAndContinue(operation string, err error)

LogAndContinue logs an error and returns true (for use in continue patterns). This replaces silent continue statements with visible logging.

Example:

if err != nil {
    errors.LogAndContinue("scanning row", err)
    continue
}

func LogAndContinueWith

func LogAndContinueWith(operation string, err error, context string)

LogAndContinueWith logs an error with additional context.

func Must

func Must[T any](v T, err error) T

Must panics if the error is not nil and returns the value otherwise. Use this only for initialization code where errors are unexpected.

func MustHandle

func MustHandle(err error)

MustHandle panics if the error is not nil. Use this only for errors that should never happen in normal operation.

func Wrap

func Wrap(op Op, err error) error

Wrap wraps an error with an operation name for context.

func WrapMsg

func WrapMsg(op Op, msg string, err error) error

WrapMsg wraps an error with an operation name and message.

Types

type Error

type Error struct {
	Op   Op     // Operation that failed
	Kind Kind   // Category of error
	Err  error  // Underlying error
	Msg  string // Additional context message
}

Error represents an application error with context.

func E

func E(args ...interface{}) *Error

E creates a new Error with the given arguments. Arguments can be: Op, Kind, error, string (message).

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error.

type Kind

type Kind uint8

Kind represents the category of error.

const (
	KindUnknown Kind = iota
	KindDatabase
	KindSearch
	KindIO
	KindValidation
	KindConfig
	KindNetwork
	KindParse
)

func GetKind

func GetKind(err error) Kind

GetKind returns the kind of an error, or KindUnknown.

func (Kind) String

func (k Kind) String() string

String returns the string representation of the error kind.

type Op

type Op string

Op represents an operation name for error context.

type RowScanner

type RowScanner struct {
	// contains filtered or unexported fields
}

RowScanner provides utilities for database row scanning with error tracking.

func NewRowScanner

func NewRowScanner(operation string) *RowScanner

NewRowScanner creates a new row scanner with error tracking.

func (*RowScanner) RecordScan

func (r *RowScanner) RecordScan()

RecordScan records a successful scan.

func (*RowScanner) RecordSkip

func (r *RowScanner) RecordSkip(err error, identifier string)

RecordSkip records a skipped row due to scan error.

func (*RowScanner) Report

func (r *RowScanner) Report()

Report logs statistics about the scanning operation.

func (*RowScanner) ScannedCount

func (r *RowScanner) ScannedCount() int

ScannedCount returns the number of successfully scanned rows.

func (*RowScanner) SkippedCount

func (r *RowScanner) SkippedCount() int

SkippedCount returns the number of skipped rows.

type SkipCounter

type SkipCounter struct {
	Op         string
	Count      int
	LastErr    error
	LastDetail string
}

SkipCounter tracks how many times operations have been skipped. Use this to provide visibility into silent error patterns.

func NewSkipCounter

func NewSkipCounter(op string) *SkipCounter

NewSkipCounter creates a new skip counter for the given operation.

func (*SkipCounter) Report

func (s *SkipCounter) Report()

Report logs a summary if any operations were skipped.

func (*SkipCounter) ReportIfAny

func (s *SkipCounter) ReportIfAny(threshold int)

ReportIfAny logs a summary only if the count exceeds threshold.

func (*SkipCounter) Skip

func (s *SkipCounter) Skip(err error, detail string)

Skip records a skipped operation due to an error.

Jump to

Keyboard shortcuts

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