Preserve operation ownership in terminal observations
This commit is contained in:
14
errors.go
14
errors.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user