argo-cd: Wrap error objects to include context

Summary

There are a lot of places in source where we return err without adding context with fmt.Errorf().

Motivation

Error messages without wrapping context are difficult to debug.

Proposal

Find places where we return unwrapped errors and add context.

Example:

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

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

This is a top-level issue and probably won’t be solved with any single PR.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@nirsht that’s precisely the sort of PR we need! I might nitpick some of the messages, but this is a huge step in the right direction. 😃

Hey @crenshaw-dev , is this something along the lines of what you’re expecting for this issue? https://github.com/argoproj/argo-cd/pull/14851 If so, I can start working on fixing it in more places.

To be clear, there are hundreds, if not thousands of places in our code base that return unwrapped errors which should be wrapped. PRs are welcome whether they’re for one or for a hundred. No need to coordinate, it’s extremely unlikely that two people will submit the same changes. 😃