aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-13 00:28:04 +0900
committerOphestra <cat@gensokyo.uk>2026-05-13 00:29:01 +0900
commit4bede7ecdddbde2de33f86c53ddf23e6abca6ffb (patch)
treed1f72996cc80c82c607d051d385c5c1573d9db74 /internal/pkg/pkg.go
parent487a03b5a3ed9a354ea4f5572c5d509b01951566 (diff)
internal/pkg: discontinue DCE resolution on signal
This serves as a stopgap measure to skip long-running DCE resolutions. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/pkg.go')
-rw-r--r--internal/pkg/pkg.go28
1 files 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()
}