Skip to content

Commit

Permalink
Add a warning for when some sources could not be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillp committed Aug 19, 2024
1 parent 53808f6 commit 2424316
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions specter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,40 @@ func (s Specter) LoadSpecifications(sources []Source) ([]Specification, error) {

// Load specifications
var specifications []Specification
var sourcesNotLoaded []Source
errs := errors.NewGroup(errors.InternalErrorCode)

for _, src := range sources {
wasLoaded := false
for _, l := range s.Loaders {
// TODO Detect sources that were not loaded by any loader
if l.SupportsSource(src) {
loaded, err := l.Load(src)
if err != nil {
s.Logger.Error(err.Error())
errs = errs.Append(err)
continue
}
specifications = append(specifications, loaded...)
if !l.SupportsSource(src) {
continue
}

loadedSpecs, err := l.Load(src)
if err != nil {
s.Logger.Error(err.Error())
errs = errs.Append(err)
continue
}

specifications = append(specifications, loadedSpecs...)
wasLoaded = true
}

if !wasLoaded {
sourcesNotLoaded = append(sourcesNotLoaded, src)
}
}

if len(sourcesNotLoaded) > 0 {
for _, src := range sourcesNotLoaded {
s.Logger.Warning(fmt.Sprintf("%s could not be loaded.", src))
}

s.Logger.Warning("%d specifications were not loaded.")
}

s.Logger.Info(fmt.Sprintf("%d specifications loaded.", len(specifications)))

return specifications, errors.GroupOrNil(errs)
Expand Down

0 comments on commit 2424316

Please sign in to comment.