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 ¶
- func IgnoreError(err error, reason string)
- func IsKind(err error, kind Kind) bool
- func LogAndContinue(operation string, err error)
- func LogAndContinueWith(operation string, err error, context string)
- func Must[T any](v T, err error) T
- func MustHandle(err error)
- func Wrap(op Op, err error) error
- func WrapMsg(op Op, msg string, err error) error
- type Error
- type Kind
- type Op
- type RowScanner
- type SkipCounter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IgnoreError ¶
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 LogAndContinue ¶
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 ¶
LogAndContinueWith logs an error with additional context.
func Must ¶
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.
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.
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 ¶
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.