Conversation
- Remove global observer variable and SetObserver function to eliminate shared state - Add observer field to Error struct with WithObserver option for explicit injection - Enhance CircuitBreaker with observer support and SetObserver method - Add NewCircuitBreakerWithObserver constructor for observer initialization - Implement observer inheritance in Wrap function to preserve observability across error chains - Add comprehensive tests for observer dependency injection patterns - Create example demonstrating new observer usage patterns with MetricsObserver This refactoring improves testability, thread safety, and maintainability by eliminating global state and making observer dependencies explicit through dependency injection. The changes maintain backward compatibility while providing a cleaner architecture.
…ucture - Move example_observer.go from package root to __examples/observer/ directory - Convert example from internal package code to standalone executable main package - Remove observer-specific functionality and simplify to basic error demonstration - Add proper import for github.com/hyp3rd/ewrap package - Add main function to make example executable - Remove circuit breaker observer usage to focus on basic error handling This change provides a cleaner project structure by separating examples from core library code and creates an executable example that demonstrates basic ewrap usage patterns.
- Add comprehensive JSON/YAML serialization for ErrorGroup with ToJSON(), ToYAML(), and MarshalJSON/MarshalYAML interfaces - Implement StackFrame struct and StackIterator for programmatic stack trace inspection - Add SerializableError type supporting metadata, stack traces, and error causality chains - Support both ewrap custom errors and standard Go errors in serialization - Include timestamped error collections with structured error representation - Add comprehensive test suite covering serialization, iteration, and edge cases - Switch to goccy/go-json for improved JSON performance - Add serialization example demonstrating new capabilities Breaking: ErrorGroup now includes additional dependencies (goccy/go-json, gopkg.in/yaml.v3)
- Update README.md with modern Go 1.25+ features and enhanced examples - Add observability.md documenting new monitoring hooks and error pattern analysis - Add serialization.md covering error group serialization and errors.Join integration - Enhance stack-traces.md with programmatic stack frame inspection and iterators - Update formatting.md with proper timestamp formatting and recovery suggestions - Modernize index.md with comprehensive feature showcase and updated examples Features documented: - Go 1.25+ optimizations (maps.Clone, slices.Clone) - Observability hooks for metrics and tracing - Stack frame iterators and structured access - Error group serialization (JSON/YAML) - Enhanced timestamp formatting options - Recovery suggestion integration - Custom retry logic with RetryInfo extension - Modern slog adapter support - errors.Join compatibility - Circuit breaker state monitoring This update brings documentation in line with the major v2.0 refactoring that adds modern Go features, observability capabilities, and enhanced error handling patterns while maintaining backward compatibility.
There was a problem hiding this comment.
Pull Request Overview
This PR documents the major v2.0 refactoring of ewrap with comprehensive documentation updates covering new observability hooks, stack frame inspection, error group serialization, and Go 1.25+ optimizations. The update modernizes the error handling library with enhanced monitoring capabilities and structured error export.
- Replace global observer pattern with component-specific observer injection
- Add programmatic stack trace inspection through iterators and structured frame access
- Implement comprehensive error group serialization for JSON/YAML export with full metadata preservation
- Switch to goccy/go-json for improved JSON performance throughout the codebase
Reviewed Changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| threshold.go | Refactors circuit breaker to use injected observers instead of global observer pattern |
| stack.go | Implements new stack frame inspection and iterator functionality |
| stack_test.go | Comprehensive test coverage for new stack frame inspection and serialization features |
| observability.go | Removes global observer pattern in favor of component-specific injection |
| observability_test.go | Updates tests to use new observer injection pattern |
| errors.go | Integrates observer and logger inheritance in error wrapping with metadata preservation |
| error_group.go | Adds comprehensive serialization capabilities with JSON/YAML export |
| go.mod | Adds goccy/go-json dependency for improved JSON performance |
| format.go | Switches to goccy/go-json from standard encoding/json |
| format_test.go | Updates import to use goccy/go-json |
| Documentation files | Extensive documentation updates covering all new features and capabilities |
Comments suppressed due to low confidence (1)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| // Skip runtime frames and error package frames | ||
| if !strings.Contains(frame.File, "runtime/") && | ||
| !strings.Contains(frame.File, "ewrap/errors.go") { |
There was a problem hiding this comment.
Hard-coded path filtering may break when the package is imported or if the file structure changes. Consider using more robust filtering based on runtime.Frame information or package names.
| !strings.Contains(frame.File, "ewrap/errors.go") { | |
| if !strings.HasPrefix(frame.Function, "runtime.") && | |
| !strings.HasPrefix(frame.Function, "ewrap.") { |
Features documented:
This update brings documentation in line with the major v2.0 refactoring
that adds modern Go features, observability capabilities, and enhanced
error handling patterns while maintaining backward compatibility.