Preserve construction error causes without extra branches
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user