Test that a load failing on a read nothing provides names every module the loaded manifests read

This commit is contained in:
2026-10-11 11:49:18 +02:00
committed by Lillem4n
parent 7f7d260f83
commit 6e2555aee6
5 changed files with 27 additions and 59 deletions
+7 -23
View File
@@ -1,18 +1,15 @@
package fejkdata
import (
"errors"
"fmt"
"strings"
)
// templateSite is a template to resolve, with its folder and its category, both empty for an
// inline template, and eachNode's label for it.
// templateSite is a template to resolve, with its folder and category, both empty for an inline
// template, and eachNode's label for it.
type templateSite struct {
t *template
folder []string
label string
category *categorySite
t *template
folder []string
label string
}
// resolveCategoryTemplates resolves every template of the categories, once all data is merged, so a
@@ -22,7 +19,7 @@ func resolveCategoryTemplates(sites []categorySite, root map[string]node) error
for _, s := range sites {
if err := eachNode(s.n, s.path, func(label string, n node) error {
if t, isTemplate := n.(*template); isTemplate {
ts = append(ts, templateSite{t: t, folder: s.dir, label: label, category: &s})
ts = append(ts, templateSite{t: t, folder: s.dir, label: label})
}
return nil
}); err != nil {
@@ -59,7 +56,7 @@ func resolveTemplates(ts []templateSite, root map[string]node) error {
for _, s := range ts {
refs, err := s.t.resolveRefs(s.folder, s.label, root)
if err != nil {
return s.withDefaultModules(err)
return err
}
s.t.refs = refs
}
@@ -90,16 +87,3 @@ func resolveTemplates(ts []templateSite, root map[string]node) error {
}
return nil
}
// Where err is a category's reference finding nothing, withDefaultModules adds the modules the
// category's source reads by default, or says it reads none.
func (s templateSite) withDefaultModules(err error) error {
var ne noEntry
if s.category == nil || !errors.As(err, &ne) {
return err
}
if modules := s.category.defaultModules; len(modules) > 0 {
return fmt.Errorf("%w; the module holding %s reads by default %s", err, s.category.path, strings.Join(modules, ", "))
}
return fmt.Errorf("%w, and the module holding %s names no module it reads by default", err, s.category.path)
}