2026-11-20 04:13:05 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2026-11-20 04:24:20 +00:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
2026-11-20 04:13:05 +00:00
|
|
|
"go.maximumdirect.net/ckconfig"
|
|
|
|
|
"go.maximumdirect.net/commandkit"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// inputError identifies an invalid Narratio request independently of native
|
|
|
|
|
// configuration diagnostics. Operational errors retain their own classification.
|
|
|
|
|
type inputError struct{ message string }
|
|
|
|
|
|
|
|
|
|
func (e *inputError) Error() string { return e.message }
|
|
|
|
|
|
|
|
|
|
func operationOutcome(err error) commandkit.Outcome {
|
|
|
|
|
if err == nil {
|
|
|
|
|
return commandkit.Success()
|
|
|
|
|
}
|
|
|
|
|
if classifyOperationError(err) == commandkit.OutcomeUsage {
|
|
|
|
|
return commandkit.Usage(err.Error()).WithCause(err)
|
|
|
|
|
}
|
|
|
|
|
return commandkit.Failure(err.Error()).WithCause(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func classifyOperationError(err error) commandkit.OutcomeKind {
|
2026-11-20 04:24:20 +00:00
|
|
|
switch err.(type) {
|
|
|
|
|
case *inputError, *config.SessionIdentityError:
|
2026-11-20 04:13:05 +00:00
|
|
|
return commandkit.OutcomeUsage
|
|
|
|
|
}
|
|
|
|
|
switch wrapped := err.(type) {
|
|
|
|
|
case interface{ Unwrap() []error }:
|
|
|
|
|
found := false
|
|
|
|
|
for _, child := range wrapped.Unwrap() {
|
|
|
|
|
if child == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
found = true
|
|
|
|
|
if classifyOperationError(child) != commandkit.OutcomeUsage {
|
|
|
|
|
return commandkit.OutcomeOperational
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if found {
|
|
|
|
|
return commandkit.OutcomeUsage
|
|
|
|
|
}
|
|
|
|
|
case interface{ Unwrap() error }:
|
|
|
|
|
if child := wrapped.Unwrap(); child != nil {
|
|
|
|
|
return classifyOperationError(child)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ckconfig.ClassifyConfigurationError(err)
|
|
|
|
|
}
|