Pawan.

software developer

back to pow

Argo CD - Error Context Wrapping

opensource·October 15, 2023 (2y ago)

The Contribution

Contributed to Argo CD by improving error handling across the codebase - wrapping error objects to include context for better debugging.

The Problem

Error messages without wrapping context are difficult to debug. There were many places in the source where errors were returned without adding context.

The Solution

Found places where unwrapped errors were returned and added context using fmt.Errorf().

Before

err := c.cache.GetItem()
if err != nil {
    return err
}

After

err := c.cache.GetItem()
if err != nil {
    return fmt.Errorf("error getting item from the cache: %w", err)
}

Impact

This improvement makes debugging easier by providing clear context about where errors originate in the codebase. Error messages now include the full chain of context, making it much easier to trace issues.

What I Learned