Improve listener failures and share configuration diagnostics
This commit is contained in:
@@ -4,12 +4,28 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
appconfig "gitea.maximumdirect.net/eric/scriptorium/internal/config"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func applicationConfigurationDiagnostics(reporter *commandkit.Reporter, result *configkit.Result[appconfig.Document], err error) commandkit.Explanation {
|
||||
var sources []configkit.SourceInfo
|
||||
var records []configkit.Diagnostic
|
||||
if result != nil {
|
||||
sources, records = result.Sources(), result.Diagnostics()
|
||||
}
|
||||
var native *configkit.LoadError
|
||||
if errors.As(err, &native) && native != nil {
|
||||
sources, records = native.Sources(), native.Diagnostics()
|
||||
}
|
||||
diagnostics, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", sources, records)
|
||||
queueDiagnostics(reporter, diagnostics)
|
||||
return explanation
|
||||
}
|
||||
|
||||
func completedRunOutcome(result *promptkit.RunResult) commandkit.Outcome {
|
||||
if result == nil {
|
||||
return commandkit.Failure("Prompt execution returned no result.").WithCause(errors.New("engine returned neither a result nor an error"))
|
||||
@@ -39,30 +55,26 @@ func requestFailure(err error, explanation commandkit.Explanation) commandkit.Ou
|
||||
message = "The operation was canceled."
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
message = "A request deadline expired."
|
||||
default:
|
||||
if ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage {
|
||||
return commandkit.Usage("Invalid configuration.", explanation.Details...).WithCause(err)
|
||||
}
|
||||
switch {
|
||||
case errors.Is(err, promptkit.ErrCapacityExceeded):
|
||||
message = "Model backend capacity is exhausted."
|
||||
case errors.Is(err, promptkit.ErrLLMGenerate):
|
||||
message = "Model generation failed."
|
||||
case errors.Is(err, promptkit.ErrValidation):
|
||||
message = "The output validation operation failed."
|
||||
case errors.Is(err, promptkit.ErrPromptNotFound):
|
||||
message = "The selected prompt was not found."
|
||||
case errors.Is(err, promptkit.ErrProfileNotFound):
|
||||
message = "The selected profile was not found."
|
||||
case errors.Is(err, promptkit.ErrArtifactLoad):
|
||||
message = "Could not load request input artifacts."
|
||||
case errors.Is(err, promptkit.ErrPromptRender):
|
||||
message = "Could not render the selected prompt."
|
||||
case errors.Is(err, promptkit.ErrInvalidRequest):
|
||||
message = "The prompt request is invalid."
|
||||
case errors.Is(err, promptkit.ErrInvalidConfig):
|
||||
message = "Could not initialize PromptKit configuration."
|
||||
}
|
||||
case ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage:
|
||||
return commandkit.Usage("Invalid configuration.", explanation.Details...).WithCause(err)
|
||||
case errors.Is(err, promptkit.ErrCapacityExceeded):
|
||||
message = "Model backend capacity is exhausted."
|
||||
case errors.Is(err, promptkit.ErrLLMGenerate):
|
||||
message = "Model generation failed."
|
||||
case errors.Is(err, promptkit.ErrValidation):
|
||||
message = "The output validation operation failed."
|
||||
case errors.Is(err, promptkit.ErrPromptNotFound):
|
||||
message = "The selected prompt was not found."
|
||||
case errors.Is(err, promptkit.ErrProfileNotFound):
|
||||
message = "The selected profile was not found."
|
||||
case errors.Is(err, promptkit.ErrArtifactLoad):
|
||||
message = "Could not load request input artifacts."
|
||||
case errors.Is(err, promptkit.ErrPromptRender):
|
||||
message = "Could not render the selected prompt."
|
||||
case errors.Is(err, promptkit.ErrInvalidRequest):
|
||||
message = "The prompt request is invalid."
|
||||
case errors.Is(err, promptkit.ErrInvalidConfig):
|
||||
message = "Could not initialize PromptKit configuration."
|
||||
}
|
||||
return commandkit.Failure(message, explanation.Details...).WithCause(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user