From 4bede7ecdddbde2de33f86c53ddf23e6abca6ffb Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 13 May 2026 00:28:04 +0900 Subject: [PATCH] internal/pkg: discontinue DCE resolution on signal This serves as a stopgap measure to skip long-running DCE resolutions. Signed-off-by: Ophestra --- internal/pkg/pkg.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 96289c9b..03528cc0 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -15,6 +15,7 @@ import ( "io/fs" "maps" "os" + "os/signal" "path/filepath" "runtime" "slices" @@ -1500,16 +1501,21 @@ type DependencyCureError []*CureError // unwrapM recursively expands underlying errors into a caller-supplied map. func (e *DependencyCureError) unwrapM( + ctx context.Context, ir *IRCache, me map[unique.Handle[ID]]*CureError, ) { for _, err := range *e { + if ctx.Err() != nil { + break + } + id := ir.Ident(err.A) if _, ok := me[id]; ok { continue } if _e, ok := err.Err.(*DependencyCureError); ok { - _e.unwrapM(ir, me) + _e.unwrapM(ctx, ir, me) continue } me[id] = err @@ -1517,9 +1523,12 @@ func (e *DependencyCureError) unwrapM( } // unwrap recursively expands and deduplicates underlying errors. -func (e *DependencyCureError) unwrap(ir *IRCache) DependencyCureError { +func (e *DependencyCureError) unwrap( + ctx context.Context, + ir *IRCache, +) DependencyCureError { me := make(map[unique.Handle[ID]]*CureError) - e.unwrapM(ir, me) + e.unwrapM(ctx, ir, me) type ent struct { id unique.Handle[ID] err *CureError @@ -1544,7 +1553,10 @@ func (e *DependencyCureError) unwrap(ir *IRCache) DependencyCureError { // Unwrap returns a deduplicated slice of underlying errors. func (e *DependencyCureError) Unwrap() []error { - errs := e.unwrap(NewIR()) + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer cancel() + + errs := e.unwrap(ctx, NewIR()) _errs := make([]error, len(errs)) for i, err := range errs { _errs[i] = err @@ -1554,8 +1566,11 @@ func (e *DependencyCureError) Unwrap() []error { // Error returns a user-facing multiline error message. func (e *DependencyCureError) Error() string { + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer cancel() + ir := NewIR() - errs := e.unwrap(ir) + errs := e.unwrap(ctx, ir) if len(errs) == 0 { return "invalid dependency cure outcome" } @@ -1566,6 +1581,9 @@ func (e *DependencyCureError) Error() string { reportName(err.A, ir.Ident(err.A)) + ": " + err.Error()) } + if ctx.Err() != nil { + buf.WriteString("\nerror resolution cancelled") + } return buf.String() }