Avoid duplicating nested error causes
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user