Avoid duplicating nested error causes
This commit is contained in:
@@ -121,7 +121,12 @@ the selected self-contained contract is not satisfied.
|
|||||||
|
|
||||||
### 3. Avoid Duplicating An Already-Retained Error Cause [P3]
|
### 3. Avoid Duplicating An Already-Retained Error Cause [P3]
|
||||||
|
|
||||||
**Status:** Open. **Stages:** 3–4.
|
**Status:** Complete. **Stages:** 3–4.
|
||||||
|
|
||||||
|
Completion: ordinary operation projection retains its mapped cause once, without
|
||||||
|
joining the original subtree a second time. Multi-engine regression coverage
|
||||||
|
checks exact cause/owner matching and one occurrence of an independent leaf;
|
||||||
|
specialized projection and redaction tests remain intact.
|
||||||
|
|
||||||
**Location:** [public error projection](../../errors.go), `mapPublicError`,
|
**Location:** [public error projection](../../errors.go), `mapPublicError`,
|
||||||
particularly lines 26–38.
|
particularly lines 26–38.
|
||||||
|
|||||||
@@ -30,12 +30,9 @@ func mapPublicError(err error) error {
|
|||||||
if errors.Is(operation.Cause, llm.ErrMalformedResponse) {
|
if errors.Is(operation.Cause, llm.ErrMalformedResponse) {
|
||||||
mapped = errors.Join(ErrMalformedResponse, mapped)
|
mapped = errors.Join(ErrMalformedResponse, mapped)
|
||||||
}
|
}
|
||||||
var internalCapacity *usecase.CapacityError
|
// The projection already retains ordinary causes; adding the original
|
||||||
var internalProvider *llm.ProviderHTTPError
|
// again would duplicate its entire subtree at each enclosing operation.
|
||||||
if errors.As(operation.Cause, &internalCapacity) || errors.As(operation.Cause, &internalProvider) {
|
return errors.Join(owner, mapped)
|
||||||
return errors.Join(owner, mapped)
|
|
||||||
}
|
|
||||||
return errors.Join(owner, mapped, operation.Cause)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mapUnownedPublicError(err)
|
return mapUnownedPublicError(err)
|
||||||
|
|||||||
@@ -3,11 +3,27 @@ package promptkit_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.maximumdirect.net/promptkit"
|
"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 }
|
type nestedErrorReader struct{ cause error }
|
||||||
|
|
||||||
func (r nestedErrorReader) Read(context.Context, promptkit.ArtifactRef) (*promptkit.Artifact, error) {
|
func (r nestedErrorReader) Read(context.Context, promptkit.ArtifactRef) (*promptkit.Artifact, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user