Files
promptkit/internal/usecase/operation_error.go

39 lines
1.1 KiB
Go
Raw Normal View History

package usecase
import (
"errors"
"fmt"
"go.maximumdirect.net/promptkit/internal/profile"
"go.maximumdirect.net/promptkit/internal/promptdef"
)
// OperationError identifies the operation that owns a failure while retaining
// the original cause for inspection.
type OperationError struct {
Category error
Cause error
}
func (e *OperationError) Error() string { return fmt.Sprintf("%v: %v", e.Category, e.Cause) }
func (e *OperationError) Unwrap() error { return e.Cause }
func (e *OperationError) Is(target error) bool { return target == e.Category }
func promptLookupError(cause error) error {
category := ErrPromptLoad
if errors.Is(cause, promptdef.ErrPromptDefinitionNotFound) {
category = promptdef.ErrPromptDefinitionNotFound
cause = fmt.Errorf("%w: %w", ErrPromptLoad, cause)
}
return &OperationError{Category: category, Cause: cause}
}
func profileLookupError(cause error) error {
category := ErrProfileLoad
if errors.Is(cause, profile.ErrProfileNotFound) {
category = profile.ErrProfileNotFound
cause = fmt.Errorf("%w: %w", ErrProfileLoad, cause)
}
return &OperationError{Category: category, Cause: cause}
}