Answer architecture round 2: each category site carries its source's default modules, set where the walk or the index loads it, and the note is written beside the resolve that finds the read; the decision states why New checks no reads

This commit is contained in:
2026-10-10 13:20:26 +02:00
committed by Lillem4n
parent 2ddba2ce96
commit 3da487f8ea
5 changed files with 42 additions and 55 deletions
+18 -17
View File
@@ -3,26 +3,18 @@ package fejkdata
import (
"errors"
"fmt"
"strings"
)
// templateSite is a template to resolve, with its folder and its category's path, both empty for an
// templateSite is a template to resolve, with its folder and its category, both empty for an
// inline template, and eachNode's label for it.
type templateSite struct {
t *template
folder []string
label string
category string
category *categorySite
}
// unresolvedRead is a reference of a category's template naming nothing.
type unresolvedRead struct {
category string
err error
}
func (u unresolvedRead) Error() string { return u.err.Error() }
func (u unresolvedRead) Unwrap() error { return u.err }
// resolveCategoryTemplates resolves every template of the categories, once all data is merged, so a
// reference sees the override-resolved tree.
func resolveCategoryTemplates(sites []categorySite, root map[string]node) error {
@@ -30,7 +22,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.path})
ts = append(ts, templateSite{t: t, folder: s.dir, label: label, category: &s})
}
return nil
}); err != nil {
@@ -66,12 +58,8 @@ type resolvedNames struct {
func resolveTemplates(ts []templateSite, root map[string]node) error {
for _, s := range ts {
refs, err := s.t.resolveRefs(s.folder, s.label, root)
var ne noEntry
if err != nil && s.category != "" && errors.As(err, &ne) {
return unresolvedRead{category: s.category, err: err}
}
if err != nil {
return err
return s.withDefaultModules(err)
}
s.t.refs = refs
}
@@ -102,3 +90,16 @@ func resolveTemplates(ts []templateSite, root map[string]node) error {
}
return nil
}
// withDefaultModules adds to err, where a reference of a category names nothing, the modules
// the category's source reads by default, or that it names 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)
}