Classify configuration acquisition errors consistently
This commit is contained in:
@@ -26,13 +26,19 @@ type processResult struct {
|
||||
func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcome {
|
||||
loaded, err := loadProcessInputs(inv.Context, input, inv.ReportingMode())
|
||||
if err != nil {
|
||||
if inv.Context.Err() != nil || llm.IsAssetError(err) {
|
||||
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
||||
if canceled := inv.Context.Err(); canceled != nil && !errors.Is(err, canceled) {
|
||||
err = errors.Join(err, canceled)
|
||||
}
|
||||
var loadErr *ck.LoadError
|
||||
if errors.As(err, &loadErr) {
|
||||
_, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", loadErr.Sources(), loadErr.Diagnostics())
|
||||
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||
if ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage {
|
||||
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||
}
|
||||
return commandkit.Failure(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||
}
|
||||
if inv.Context.Err() != nil || llm.IsAssetError(err) {
|
||||
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
||||
}
|
||||
return commandkit.Usage(err.Error()).WithCause(err)
|
||||
}
|
||||
|
||||
@@ -60,6 +60,32 @@ func TestMalformedCompanionReturnsInputFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnreadableCompanionReturnsOperationalFailure(t *testing.T) {
|
||||
main := writeRuntimeErrorConfig(t, "profiles: []\n")
|
||||
companion := filepath.Join(filepath.Dir(main), "prompts.yml")
|
||||
if err := os.Chmod(companion, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.ReadFile(companion); !errors.Is(err, os.ErrPermission) {
|
||||
t.Skipf("file permissions do not prevent reads: %v", err)
|
||||
}
|
||||
transcript := filepath.Join(filepath.Dir(main), "transcript.json")
|
||||
if err := os.WriteFile(transcript, []byte("[]\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, args := range [][]string{
|
||||
{"promptkit", "list", "prompts"},
|
||||
{"config", "show", "--scope", "promptkit"},
|
||||
{"process", transcript},
|
||||
} {
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := Run(context.Background(), append(args, "--config", main), &stdout, &stderr)
|
||||
if code != 1 || !strings.Contains(stderr.String(), "source.permission") || !strings.Contains(stderr.String(), "prompts.yml") || stdout.Len() != 0 {
|
||||
t.Errorf("%v: status=%d want=1 stdout=%q stderr=%q", args, code, stdout.String(), stderr.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceCommandKeepsCallerCancellationAsFailure(t *testing.T) {
|
||||
main := writeRuntimeErrorConfig(t, "profiles:\n - id: proposal\n model: local-model\n")
|
||||
transcript := filepath.Join(filepath.Dir(main), "transcript.json")
|
||||
|
||||
Reference in New Issue
Block a user