Track the operation owning internal errors
This commit is contained in:
34
internal/usecase/operation_error_test.go
Normal file
34
internal/usecase/operation_error_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package usecase
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/promptkit/internal/profile"
|
||||
"go.maximumdirect.net/promptkit/internal/promptdef"
|
||||
)
|
||||
|
||||
func TestOperationErrorRetainsOwnerAndCause(t *testing.T) {
|
||||
cause := fmt.Errorf("nested: %w", promptdef.ErrPromptDefinitionNotFound)
|
||||
outer := &OperationError{Category: ErrLLMGenerate, Cause: cause}
|
||||
if !errors.Is(outer, ErrLLMGenerate) || !errors.Is(outer, promptdef.ErrPromptDefinitionNotFound) || errors.Unwrap(outer) != cause {
|
||||
t.Fatalf("operation error = %v", outer)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
err error
|
||||
category error
|
||||
}{
|
||||
{promptLookupError(cause), promptdef.ErrPromptDefinitionNotFound},
|
||||
{profileLookupError(profile.ErrProfileNotFound), profile.ErrProfileNotFound},
|
||||
{promptLookupError(contextFailure), ErrPromptLoad},
|
||||
{profileLookupError(contextFailure), ErrProfileLoad},
|
||||
} {
|
||||
var operation *OperationError
|
||||
if !errors.As(test.err, &operation) || operation.Category != test.category {
|
||||
t.Errorf("operation = %+v", operation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var contextFailure = errors.New("lookup failed")
|
||||
Reference in New Issue
Block a user