Avoid duplicating nested error causes

This commit is contained in:
2026-11-05 16:00:39 +00:00
parent ac1e150168
commit 4aeb58f913
3 changed files with 25 additions and 7 deletions

View File

@@ -3,11 +3,27 @@ package promptkit_test
import (
"context"
"errors"
"strings"
"testing"
"go.maximumdirect.net/promptkit"
)
func TestNestedErrorsRetainEachCauseWithoutDuplicatingDiagnostics(t *testing.T) {
cause := errors.New("independent-leaf-diagnostic")
for range 10 {
parent := newSimpleEngine(t, "parent", promptkit.WithLLMClient(&fakeLLMClient{err: cause}))
_, err := parent.Run(context.Background(), promptkit.RunRequest{PromptID: "prompt"})
if !errors.Is(err, cause) || !errors.Is(err, promptkit.ErrLLMGenerate) {
t.Fatalf("lost owner or cause: %v", err)
}
if strings.Count(err.Error(), "independent-leaf-diagnostic") != 1 {
t.Fatalf("duplicated leaf: %v", err)
}
cause = err
}
}
type nestedErrorReader struct{ cause error }
func (r nestedErrorReader) Read(context.Context, promptkit.ArtifactRef) (*promptkit.Artifact, error) {