Preserve construction error causes without extra branches

This commit is contained in:
2026-11-16 19:44:09 +00:00
parent fcbff80ab2
commit 4939fdb283
4 changed files with 75 additions and 9 deletions

View File

@@ -10,6 +10,25 @@ import (
"go.maximumdirect.net/promptkit/internal/usecase"
)
func TestConstructionErrorPreservesJoinedCause(t *testing.T) {
operational := errors.New("independent operational failure")
cause := errors.Join(operational, context.Canceled)
engine, err := NewEngine(Config{}, optionFunc(func(*engineOptions) error {
return cause
}))
if engine != nil || err == nil {
t.Fatalf("construction = (%#v, %v), want failure", engine, err)
}
if unwrapped := errors.Unwrap(err); unwrapped != cause {
t.Fatalf("construction cause = %v, want the unchanged joined cause", unwrapped)
}
for _, target := range []error{ErrInvalidConfig, operational, context.Canceled} {
if !errors.Is(err, target) {
t.Errorf("construction error = %v, want identity %v", err, target)
}
}
}
func TestMapPublicErrorPreservesGenerationCancellation(t *testing.T) {
internalErr := fmt.Errorf("%w: %w", usecase.ErrLLMGenerate, context.Canceled)