Preserve native glossary loading error classifications

This commit is contained in:
2026-11-26 21:14:32 +00:00
parent bf3184cf0a
commit 4b1812995f
5 changed files with 34 additions and 14 deletions

View File

@@ -32,8 +32,7 @@ func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcom
var loadErr *ck.LoadError
if errors.As(err, &loadErr) {
_, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", loadErr.Sources(), loadErr.Diagnostics())
var glossaryErr *appconfig.GlossaryInputError
if inv.Context.Err() == nil && (errors.As(err, &glossaryErr) || ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage) {
if inv.Context.Err() == nil && ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage {
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
}
return commandkit.Failure(loadErr.Error(), explanation.Details...).WithCause(err)

View File

@@ -76,15 +76,25 @@ func TestProcessRuntimeGlossaryFailures(t *testing.T) {
t.Fatal(err)
}
}
for _, name := range []string{"missing.yml", "bad.yml", "empty.yml"} {
for _, tc := range []struct {
name string
status int
diagnostic string
}{
{"missing.yml", 1, "source.missing"},
{"bad.yml", 2, "yaml.invalid"},
{"empty.yml", 2, "no glossary entries"},
} {
var stdout, stderr bytes.Buffer
output := filepath.Join(dir, "output.json")
status := Run(context.Background(), []string{"process", "--config", filepath.Join(dir, "config.yml"), "--glossary-file", filepath.Join(dir, name), "--output", output, filepath.Join(dir, "input.json")}, &stdout, &stderr)
if status != 2 {
t.Fatalf("%s: status=%d stderr=%s", name, status, stderr.String())
status := Run(context.Background(), []string{"process", "--config", filepath.Join(dir, "config.yml"), "--glossary-file", filepath.Join(dir, tc.name), "--output", output, filepath.Join(dir, "input.json")}, &stdout, &stderr)
if status != tc.status || !strings.Contains(stderr.String(), tc.diagnostic) {
t.Fatalf("%s: status=%d stderr=%s", tc.name, status, stderr.String())
}
if _, err := os.Stat(output); !os.IsNotExist(err) {
t.Fatalf("%s: output prepared: %v", name, err)
for _, name := range []string{"output.json", "errors.yml", "recoveries.yml", "report.md"} {
if _, err := os.Stat(filepath.Join(dir, name)); !os.IsNotExist(err) {
t.Fatalf("%s: output %s prepared: %v", tc.name, name, err)
}
}
}
}