Skip to content

Error() should not panic when errs is nil; return a clear error instead #24

@sourcery-ai

Description

@sourcery-ai

Currently, the Error() function panics when errs is nil. This can be risky, especially if Error() is called unexpectedly during error handling, as it may lead to application crashes. Instead of panicking, the function should return a clear error message or a sentinel error value to safely handle the nil case and avoid unexpected panics.

Suggested Fix:

  • Update the Error() function to check if errs is nil and, if so, return a descriptive error message or a sentinel error value instead of panicking.

Action Items:

  • Refactor the Error() function to remove the panic on nil errs.
  • Add tests to verify the new behavior when errs is nil.
  • Document the change in the function's comments or documentation.

I created this issue for @MusicalNinjaDad from #23 (comment).

Tips and commands

Getting Help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions