errs

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package errs provides error context enrichment, grouping, learning, patterns, and recovery for the hawk engine.

Named "errs" (not "error") to avoid shadowing the builtin error type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPattern

func ExtractPattern(errorMsg string) string

func FormatError

func FormatError(enriched *EnrichedError) string

func NormalizeError

func NormalizeError(msg string) string

Types

type EnrichedError

type EnrichedError struct {
	Original    string
	Title       string
	Explanation string
	Suggestions []string
	Examples    []string
	Severity    string
	Recoverable bool
}

type ErrorContext

type ErrorContext struct {
	Patterns map[string]*ErrorHelp
	// contains filtered or unexported fields
}

func NewErrorContext

func NewErrorContext() *ErrorContext

func (*ErrorContext) AddPattern

func (ec *ErrorContext) AddPattern(pattern string, help ErrorHelp) error

func (*ErrorContext) Enrich

func (ec *ErrorContext) Enrich(err string) *EnrichedError

func (*ErrorContext) IsRecoverable

func (ec *ErrorContext) IsRecoverable(err string) bool

func (*ErrorContext) SuggestFix

func (ec *ErrorContext) SuggestFix(err string) string

type ErrorGroup

type ErrorGroup struct {
	ID         string          `json:"id"`
	Pattern    string          `json:"pattern"`
	Instances  []ErrorInstance `json:"instances"`
	Count      int             `json:"count"`
	FirstSeen  time.Time       `json:"first_seen"`
	LastSeen   time.Time       `json:"last_seen"`
	Resolution string          `json:"resolution"`
	Status     string          `json:"status"`
}

type ErrorGrouper

type ErrorGrouper struct {
	Groups map[string]*ErrorGroup
	// contains filtered or unexported fields
}

func NewErrorGrouper

func NewErrorGrouper() *ErrorGrouper

func (*ErrorGrouper) Add

func (eg *ErrorGrouper) Add(errorMsg, file string, line int, context string) *ErrorGroup

func (*ErrorGrouper) FindGroup

func (eg *ErrorGrouper) FindGroup(errorMsg string) *ErrorGroup

func (*ErrorGrouper) FormatGroups

func (eg *ErrorGrouper) FormatGroups() string

func (*ErrorGrouper) GetActive

func (eg *ErrorGrouper) GetActive() []*ErrorGroup

func (*ErrorGrouper) GetResolution

func (eg *ErrorGrouper) GetResolution(errorMsg string) string

func (*ErrorGrouper) IsKnown

func (eg *ErrorGrouper) IsKnown(errorMsg string) bool

func (*ErrorGrouper) MarkResolved

func (eg *ErrorGrouper) MarkResolved(groupID, resolution string)

func (*ErrorGrouper) Prune

func (eg *ErrorGrouper) Prune(maxAge time.Duration)

type ErrorHelp

type ErrorHelp struct {
	Pattern     *regexp.Regexp
	Title       string
	Explanation string
	Suggestions []string
	Examples    []string
	DocURL      string
	AutoFix     string
}

type ErrorInstance

type ErrorInstance struct {
	Message   string    `json:"message"`
	File      string    `json:"file"`
	Line      int       `json:"line"`
	Timestamp time.Time `json:"timestamp"`
	Context   string    `json:"context"`
}

type ErrorLearner

type ErrorLearner struct {
	Patterns map[string]*LearnedPattern
	// contains filtered or unexported fields
}

func NewErrorLearner

func NewErrorLearner() *ErrorLearner

func (*ErrorLearner) BuildFixSuggestion

func (el *ErrorLearner) BuildFixSuggestion(errorMsg string) string

func (*ErrorLearner) Export

func (el *ErrorLearner) Export() ([]byte, error)

func (*ErrorLearner) Import

func (el *ErrorLearner) Import(data []byte) error

func (*ErrorLearner) Learn

func (el *ErrorLearner) Learn(errorMsg, fix, language, category string)

func (*ErrorLearner) MatchLearned

func (el *ErrorLearner) MatchLearned(errorMsg string) []*LearnedPattern

func (*ErrorLearner) PruneWeak

func (el *ErrorLearner) PruneWeak(minConfidence float64)

func (*ErrorLearner) RecordFailure

func (el *ErrorLearner) RecordFailure(patternID string)

func (*ErrorLearner) RecordSuccess

func (el *ErrorLearner) RecordSuccess(patternID string)

func (*ErrorLearner) Stats

func (el *ErrorLearner) Stats() ErrorLearnerStats

type ErrorLearnerStats

type ErrorLearnerStats struct {
	TotalPatterns int            `json:"total_patterns"`
	ByCategory    map[string]int `json:"by_category"`
	ByLanguage    map[string]int `json:"by_language"`
	AvgConfidence float64        `json:"avg_confidence"`
}

type ErrorPattern

type ErrorPattern struct {
	Trigger    string    `json:"trigger"`
	RootCause  string    `json:"root_cause"`
	Resolution string    `json:"resolution"`
	HitCount   int       `json:"hit_count"`
	LastSeen   time.Time `json:"last_seen"`
}

type ErrorPatternDB

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

func NewErrorPatternDB

func NewErrorPatternDB() *ErrorPatternDB

func (*ErrorPatternDB) FormatHints

func (db *ErrorPatternDB) FormatHints(errorMsg string) string

func (*ErrorPatternDB) Match

func (db *ErrorPatternDB) Match(errorMsg string) []ErrorPattern

func (*ErrorPatternDB) Record

func (db *ErrorPatternDB) Record(trigger, rootCause, resolution string)

type ErrorRecovery

type ErrorRecovery struct {
	Strategies  map[string]*RecoveryStrategy
	History     []RecoveryAttempt
	MaxAttempts int
	// contains filtered or unexported fields
}

func NewErrorRecovery

func NewErrorRecovery() *ErrorRecovery

func (*ErrorRecovery) BuildRecoveryPrompt

func (er *ErrorRecovery) BuildRecoveryPrompt(result *RecoveryResult) string

func (*ErrorRecovery) FormatHistory

func (er *ErrorRecovery) FormatHistory(limit int) string

func (*ErrorRecovery) Recover

func (er *ErrorRecovery) Recover(err error, ctx *RecoveryContext) (*RecoveryResult, error)

func (*ErrorRecovery) RegisterStrategy

func (er *ErrorRecovery) RegisterStrategy(strategy *RecoveryStrategy)

func (*ErrorRecovery) ShouldRetry

func (er *ErrorRecovery) ShouldRetry(err error) bool

func (*ErrorRecovery) SuccessRate

func (er *ErrorRecovery) SuccessRate() float64

type LearnedPattern

type LearnedPattern struct {
	ID           string    `json:"id"`
	Category     string    `json:"category"`
	Language     string    `json:"language"`
	Pattern      string    `json:"pattern"`
	Example      string    `json:"example"`
	Fix          string    `json:"fix"`
	FixTemplate  string    `json:"fix_template"`
	Confidence   float64   `json:"confidence"`
	SuccessCount int       `json:"success_count"`
	FailureCount int       `json:"failure_count"`
	LastSeen     time.Time `json:"last_seen"`
}

type RecoveryAttempt

type RecoveryAttempt struct {
	Error     string
	Strategy  string
	Recovered bool
	Duration  time.Duration
	Timestamp time.Time
}

type RecoveryContext

type RecoveryContext struct {
	Error         error
	ErrorMsg      string
	LastToolCall  string
	LastArgs      map[string]interface{}
	Messages      []string
	FilesModified []string
	Attempt       int
}

type RecoveryResult

type RecoveryResult struct {
	Recovered bool
	Action    string
	Message   string
	RetryWith string
}

type RecoveryStrategy

type RecoveryStrategy struct {
	Name         string
	ErrorPattern *regexp.Regexp
	RecoverFn    func(err error, context *RecoveryContext) (*RecoveryResult, error)
	Priority     int
	SuccessCount int
	FailureCount int
}

Jump to

Keyboard shortcuts

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