Restructured project for V2 refactor: **Structure Changes:** - Moved all V1 code to orig/ folder (preserved with git mv) - Created docs/planning/ directory - Added orig/README_V1.md explaining V1 preservation **Planning Documents:** - 00_V2_MASTER_PLAN.md: Complete architecture overview - Executive summary of critical V1 issues - High-level component architecture diagrams - 5-phase implementation roadmap - Success metrics and risk mitigation - 07_TASK_BREAKDOWN.md: Atomic task breakdown - 99+ hours of detailed tasks - Every task < 2 hours (atomic) - Clear dependencies and success criteria - Organized by implementation phase **V2 Key Improvements:** - Per-exchange parsers (factory pattern) - Multi-layer strict validation - Multi-index pool cache - Background validation pipeline - Comprehensive observability **Critical Issues Addressed:** - Zero address tokens (strict validation + cache enrichment) - Parsing accuracy (protocol-specific parsers) - No audit trail (background validation channel) - Inefficient lookups (multi-index cache) - Stats disconnection (event-driven metrics) Next Steps: 1. Review planning documents 2. Begin Phase 1: Foundation (P1-001 through P1-010) 3. Implement parsers in Phase 2 4. Build cache system in Phase 3 5. Add validation pipeline in Phase 4 6. Migrate and test in Phase 5 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
109 lines
2.3 KiB
Go
109 lines
2.3 KiB
Go
package errors
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
// WrapContextError wraps a context error with detailed information about the operation
|
|
// that failed, including the function name, parameters, and call location.
|
|
//
|
|
// Example usage:
|
|
//
|
|
// if ctx.Err() != nil {
|
|
// return errors.WrapContextError(ctx.Err(), "fetchTransactionReceipt",
|
|
// map[string]interface{}{
|
|
// "txHash": txHash.Hex(),
|
|
// "attempt": attempt,
|
|
// "maxRetries": maxRetries,
|
|
// })
|
|
// }
|
|
func WrapContextError(err error, functionName string, params map[string]interface{}) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
|
|
// Get caller information
|
|
pc, file, line, ok := runtime.Caller(1)
|
|
funcName := "unknown"
|
|
if ok {
|
|
fn := runtime.FuncForPC(pc)
|
|
if fn != nil {
|
|
funcName = fn.Name()
|
|
}
|
|
}
|
|
|
|
// Build detailed error message
|
|
msg := fmt.Sprintf("context error in %s", functionName)
|
|
|
|
// Add parameters
|
|
if len(params) > 0 {
|
|
msg += " ["
|
|
first := true
|
|
for key, value := range params {
|
|
if !first {
|
|
msg += ", "
|
|
}
|
|
msg += fmt.Sprintf("%s=%v", key, value)
|
|
first = false
|
|
}
|
|
msg += "]"
|
|
}
|
|
|
|
// Add caller location
|
|
if ok {
|
|
msg += fmt.Sprintf(" (at %s:%d in %s)", file, line, funcName)
|
|
}
|
|
|
|
// Determine context error type
|
|
var errType string
|
|
switch err {
|
|
case context.Canceled:
|
|
errType = "context canceled"
|
|
case context.DeadlineExceeded:
|
|
errType = "context deadline exceeded"
|
|
default:
|
|
errType = fmt.Sprintf("%v", err)
|
|
}
|
|
|
|
return fmt.Errorf("%s: %s", msg, errType)
|
|
}
|
|
|
|
// WrapContextErrorf wraps a context error with a formatted message and parameters
|
|
func WrapContextErrorf(err error, format string, args ...interface{}) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
|
|
// Get caller information
|
|
pc, file, line, ok := runtime.Caller(1)
|
|
funcName := "unknown"
|
|
if ok {
|
|
fn := runtime.FuncForPC(pc)
|
|
if fn != nil {
|
|
funcName = fn.Name()
|
|
}
|
|
}
|
|
|
|
msg := fmt.Sprintf(format, args...)
|
|
|
|
// Add caller location
|
|
if ok {
|
|
msg += fmt.Sprintf(" (at %s:%d in %s)", file, line, funcName)
|
|
}
|
|
|
|
// Determine context error type
|
|
var errType string
|
|
switch err {
|
|
case context.Canceled:
|
|
errType = "context canceled"
|
|
case context.DeadlineExceeded:
|
|
errType = "context deadline exceeded"
|
|
default:
|
|
errType = fmt.Sprintf("%v", err)
|
|
}
|
|
|
|
return fmt.Errorf("%s: %s", msg, errType)
|
|
}
|