Skip to content

v2: Improve error handling with typed errors and context #255

@mmcdole

Description

@mmcdole

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions