Preserve operation ownership in terminal observations

This commit is contained in:
2026-11-05 16:03:26 +00:00
parent 3f93763c9c
commit 1ff6d778af
6 changed files with 108 additions and 24 deletions

View File

@@ -13,6 +13,18 @@ import (
"go.maximumdirect.net/promptkit/internal/usecase"
)
// publicOperationError keeps classification separate from inspectable causes.
// Cache wording so formatting nested operations does not repeatedly rebuild it.
type publicOperationError struct {
owner error
cause error
message string
}
func (e *publicOperationError) Error() string { return e.message }
func (e *publicOperationError) Unwrap() error { return e.cause }
func (e *publicOperationError) Is(target error) bool { return errors.Is(e.owner, target) }
func mapPublicError(err error) error {
if err == nil {
return nil
@@ -32,7 +44,7 @@ func mapPublicError(err error) error {
}
// The projection already retains ordinary causes; adding the original
// again would duplicate its entire subtree at each enclosing operation.
return errors.Join(owner, mapped)
return &publicOperationError{owner: owner, cause: mapped, message: fmt.Sprintf("%v: %v", owner, mapped)}
}
}
return mapUnownedPublicError(err)