-
Notifications
You must be signed in to change notification settings - Fork 214
Open
Labels
Description
Overview
Implement a comprehensive error handling system with typed errors that provide context about parsing failures, making debugging easier and enabling better error recovery strategies.
Tasks
Error Types
- Define error types for different failure categories:
ParseError
- Malformed XML/JSON structureValidationError
- Missing required fields, invalid valuesNetworkError
- HTTP failures, timeouts (already have HTTPError)FormatError
- Unknown feed type, unsupported versionExtensionError
- Problems parsing extensions
Error Context
- Include parse location (line/column) when available
- Include field/element path that caused error
- Include raw content snippet around error
- Make errors chainable with
errors.Is()
anderrors.As()
Strictness Integration
- Errors should be strictness-aware
- Issues ignored in lenient mode become errors in strict mode
Example Usage
feed, err := parser.Parse(reader, opts)
if err != nil {
var parseErr *gofeed.ParseError
if errors.As(err, &parseErr) {
fmt.Printf("Parse error at line %d: %s\n", parseErr.Line, parseErr.Message)
fmt.Printf("Context: %s\n", parseErr.Context)
}
}
Benefits
- Easier debugging with specific error information
- Better error messages for end users
- Programmatic error handling based on error type
- Improved logging and monitoring capabilities
Related Issues
- Part of v2 RFC (RFC: gofeed v2 – Proposed Changes #241)
- Works with strictness controls (v2: Add parsing strictness configuration #250)