internal/pkg: hold artifact in DCE
All checks were successful
Test / Create distribution (push) Successful in 1m3s
Test / Sandbox (push) Successful in 2m42s
Test / ShareFS (push) Successful in 3m43s
Test / Hakurei (push) Successful in 3m56s
Test / Sandbox (race detector) (push) Successful in 5m20s
Test / Hakurei (race detector) (push) Successful in 6m24s
Test / Flake checks (push) Successful in 1m21s

This is significantly slower but enables much better error reporting.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-12 19:45:25 +09:00
parent a6008ef68b
commit a167c1aba5
3 changed files with 67 additions and 58 deletions

View File

@@ -1485,8 +1485,8 @@ func (c *Cache) Cure(a Artifact) (
// CureError wraps a non-nil error returned attempting to cure an [Artifact].
type CureError struct {
Ident unique.Handle[ID]
Err error
A Artifact
Err error
}
// Unwrap returns the underlying error.
@@ -1499,22 +1499,22 @@ func (e *CureError) Error() string { return e.Err.Error() }
type DependencyCureError []*CureError
// unwrapM recursively expands underlying errors into a caller-supplied map.
func (e *DependencyCureError) unwrapM(me map[unique.Handle[ID]]*CureError) {
func (e *DependencyCureError) unwrapM(me map[Artifact]*CureError) {
for _, err := range *e {
if _, ok := me[err.Ident]; ok {
if _, ok := me[err.A]; ok {
continue
}
if _e, ok := err.Err.(*DependencyCureError); ok {
_e.unwrapM(me)
continue
}
me[err.Ident] = err
me[err.A] = err
}
}
// unwrap recursively expands and deduplicates underlying errors.
func (e *DependencyCureError) unwrap() DependencyCureError {
me := make(map[unique.Handle[ID]]*CureError)
me := make(map[Artifact]*CureError)
e.unwrapM(me)
errs := slices.AppendSeq(
make(DependencyCureError, 0, len(me)),
@@ -1522,8 +1522,9 @@ func (e *DependencyCureError) unwrap() DependencyCureError {
)
var identBuf [2]ID
ir := NewIR()
slices.SortFunc(errs, func(a, b *CureError) int {
identBuf[0], identBuf[1] = a.Ident.Value(), b.Ident.Value()
identBuf[0], identBuf[1] = ir.Ident(a.A).Value(), ir.Ident(b.A).Value()
return slices.Compare(identBuf[0][:], identBuf[1][:])
})
@@ -1548,8 +1549,11 @@ func (e *DependencyCureError) Error() string {
}
var buf strings.Builder
buf.WriteString("errors curing dependencies:")
ir := NewIR()
for _, err := range errs {
buf.WriteString("\n\t" + Encode(err.Ident.Value()) + ": " + err.Error())
buf.WriteString("\n\t" +
reportName(err.A, ir.Ident(err.A)) + ": " +
err.Error())
}
return buf.String()
}
@@ -2082,7 +2086,7 @@ func (pending *pendingArtifactDep) cure(c *Cache) {
}
pending.errsMu.Lock()
*pending.errs = append(*pending.errs, &CureError{c.Ident(pending.a), err})
*pending.errs = append(*pending.errs, &CureError{pending.a, err})
pending.errsMu.Unlock()
}