gojekfarm / xtools

XTools is a submodule based repo to host re-usable Golang code.
MIT License
7 stars 0 forks source link

feat: include more context in errors #31

Closed ajatprabha closed 8 months ago

ajatprabha commented 8 months ago

Current errors do not provide much info into where to look for malformed values. This change aims to provide more context around errors.

codecov-commenter commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (0020145) 98.97% compared to head (919eca4) 98.85%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #31 +/- ## ========================================== - Coverage 98.97% 98.85% -0.12% ========================================== Files 35 36 +1 Lines 781 789 +8 ========================================== + Hits 773 780 +7 - Misses 8 9 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonnes commented 8 months ago

Is it possible to support errors.Is? Something like

if errors.Is(err, xload.ErrRequired):
   ...
ajatprabha commented 8 months ago

Is it possible to support errors.Is? Something like

if errors.Is(err, xload.ErrRequired):
   ...

errors.Is would not work as it cannot work with struct types but only initialized variables, errors.As will work instead, syntax would look like:

var reqErr xload.ErrRequired
if errors.As(err, &reqErr) {
    ...
}