libopenapi icon indicating copy to clipboard operation
libopenapi copied to clipboard

feat: Public methods now return MultiError instead of []error

Open thrawn01 opened this issue 1 year ago • 4 comments

Purpose

The current code base returns multiple errors which is inconvenient to use if multiple errors are not useful to the caller. Instead this PR creates an error that implements the Unwrap() []error method which can be used to retrieve multiple errors. This interface was introduced in go 1.20

Implementation

  • Added type MultiError struct
  • Added errorMsg() and errorMsgf() (Although that could be narrowed down to just errorMsg() with the capability to handle optional formatted text)

Versioning

This PR significantly breaks compatibility of the public interfaces. If this PR is acceptable, we should bump to v1 before merging.

Postscript

My editor naturally indents with a TAB, and as this project uses SPACES for indentation this PR mixes TABS and SPACES. If this PR is to be accepted I'll fix accordingly.

Reference: https://github.com/pb33f/libopenapi/issues/117

thrawn01 avatar May 30 '23 20:05 thrawn01

Thank you very much for doing this work. I know the change is small, but as you correctly determined, it's a large breaking change for existing consumers - however, it's the right change to make.

We will keep this PR warm until we're ready for 1.0, it should stay healthy and rebase easily when it comes time.

Thank you for your contribution.

(The build is failing btw :-)

daveshanley avatar May 31 '23 10:05 daveshanley

Codecov Report

Patch coverage: 97.01% and no project coverage change.

Comparison is base (a4b7a01) 99.77% compared to head (7c8dcb0) 99.77%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #123   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files         146      147    +1     
  Lines       10174    10198   +24     
=======================================
+ Hits        10151    10175   +24     
  Misses         23       23           
Flag Coverage Δ
unittests 99.77% <97.01%> (+<0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
document.go 97.95% <94.73%> (-0.10%) :arrow_down:
error.go 100.00% <100.00%> (ø)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Jun 01 '23 10:06 codecov[bot]

@thrawn01 do you have time to address the build issues and conflicts?

n0rig avatar Nov 14 '23 14:11 n0rig

I unfortunately do not, not until the end of the year Feel free to close or take the code as is if you want to use this code as the basis for a new PR.

No need to credit me.

thrawn01 avatar Nov 14 '23 22:11 thrawn01