@@ -69,6 +69,16 @@ type Error struct {
6969 Code Code
7070}
7171
72+ // LevelErrors represents Errors filtered into fatal and warnings.
73+ type LevelErrors struct {
74+ // Warnings holds Errors that were below a compliance-level threshold.
75+ Warnings []* Error
76+
77+ // Error holds errors that were at or above a compliance-level
78+ // threshold, as well as errors that are not Errors.
79+ Error * multierror.Error
80+ }
81+
7282var (
7383 containerFormatRef = func (version string ) (reference string , err error ) {
7484 return fmt .Sprintf (referenceTemplate , version , "bundle.md#container-format" ), nil
@@ -168,3 +178,23 @@ func FindError(err error, code Code) Code {
168178 }
169179 return NonRFCError
170180}
181+
182+ // SplitLevel removes RFC 2119 errors with a level less than 'level'
183+ // from the source error. If the source error is not a multierror, it
184+ // is returned unchanged.
185+ func SplitLevel (errIn error , level rfc2119.Level ) (levelErrors LevelErrors , errOut error ) {
186+ merr , ok := errIn .(* multierror.Error )
187+ if ! ok {
188+ return levelErrors , errIn
189+ }
190+ for _ , err := range merr .Errors {
191+ e , ok := err .(* Error )
192+ if ok && e .Err .Level < level {
193+ fmt .Println (e )
194+ levelErrors .Warnings = append (levelErrors .Warnings , e )
195+ continue
196+ }
197+ levelErrors .Error = multierror .Append (levelErrors .Error , err )
198+ }
199+ return levelErrors , nil
200+ }
0 commit comments