Use native configuration validation and diagnostics
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// inputError identifies an invalid Narratio request independently of native
|
||||
@@ -29,7 +30,7 @@ func operationOutcome(err error) commandkit.Outcome {
|
||||
|
||||
func classifyOperationError(err error) commandkit.OutcomeKind {
|
||||
switch err.(type) {
|
||||
case *inputError, *config.SessionIdentityError, *config.ArtifactCatalogInputError:
|
||||
case *inputError, *config.ArtifactCatalogInputError:
|
||||
return commandkit.OutcomeUsage
|
||||
}
|
||||
switch wrapped := err.(type) {
|
||||
@@ -54,3 +55,37 @@ func classifyOperationError(err error) commandkit.OutcomeKind {
|
||||
}
|
||||
return ckconfig.ClassifyConfigurationError(err)
|
||||
}
|
||||
|
||||
// reportOperationOutcome leaves native configuration evidence to ckconfig while
|
||||
// retaining the operation's context and any joined cleanup or persistence causes.
|
||||
func reportOperationOutcome(inv commandkit.Invocation, err error) commandkit.Outcome {
|
||||
outcome := operationOutcome(err)
|
||||
var details []commandkit.Detail
|
||||
var visit func(error)
|
||||
visit = func(e error) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
if load, ok := e.(*configkit.LoadError); ok {
|
||||
warnings, explanation := ckconfig.AdaptDiagnostics("Configuration:\n", load.Sources(), load.Diagnostics())
|
||||
for _, warning := range warnings {
|
||||
_ = inv.Reporter().Warn("", warning.Write)
|
||||
}
|
||||
details = append(details, explanation.Details...)
|
||||
return
|
||||
}
|
||||
switch wrapped := e.(type) {
|
||||
case interface{ Unwrap() []error }:
|
||||
for _, child := range wrapped.Unwrap() {
|
||||
visit(child)
|
||||
}
|
||||
case interface{ Unwrap() error }:
|
||||
visit(wrapped.Unwrap())
|
||||
}
|
||||
}
|
||||
visit(err)
|
||||
if len(details) > 0 {
|
||||
outcome = outcome.WithExplanation(err.Error(), details...)
|
||||
}
|
||||
return outcome
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user