gofeed icon indicating copy to clipboard operation
gofeed copied to clipboard

v2: Improve error handling with typed errors and context

Open mmcdole opened this issue 7 months ago • 0 comments

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 structure
    • ValidationError - Missing required fields, invalid values
    • NetworkError - HTTP failures, timeouts (already have HTTPError)
    • FormatError - Unknown feed type, unsupported version
    • ExtensionError - 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() and errors.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 (#241)
  • Works with strictness controls (#250)

mmcdole avatar May 26 '25 14:05 mmcdole