Classify invalid artifact relations as input errors
This commit is contained in:
@@ -29,7 +29,7 @@ func operationOutcome(err error) commandkit.Outcome {
|
||||
|
||||
func classifyOperationError(err error) commandkit.OutcomeKind {
|
||||
switch err.(type) {
|
||||
case *inputError, *config.SessionIdentityError:
|
||||
case *inputError, *config.SessionIdentityError, *config.ArtifactCatalogInputError:
|
||||
return commandkit.OutcomeUsage
|
||||
}
|
||||
switch wrapped := err.(type) {
|
||||
|
||||
@@ -114,11 +114,21 @@ func TestOperationOutcomePreservesCausesAndOperationalPrecedence(t *testing.T) {
|
||||
}
|
||||
input := &inputError{message: "invalid identity selection"}
|
||||
operational := errors.New("storage unavailable")
|
||||
_, catalogInput := config.DeriveArtifactCatalog(&config.PipelineConfig{Scriptorium: &config.ScriptoriumConfig{Artifacts: map[string]config.ScriptoriumArtifactConfig{
|
||||
"result": {OutputPath: "artifacts/result.md", DependsOn: []string{"missing"}},
|
||||
}}}, config.ResolvedParty{})
|
||||
var catalogError *config.ArtifactCatalogInputError
|
||||
if !errors.As(catalogInput, &catalogError) || errors.Unwrap(catalogError) == nil {
|
||||
t.Fatalf("catalog validation lost its typed input cause: %v", catalogInput)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
err error
|
||||
status int
|
||||
}{
|
||||
{nil, 0}, {input, 2}, {invalid, 2},
|
||||
{catalogInput, 2},
|
||||
{errors.Join(catalogInput, operational), 1},
|
||||
{errors.Join(catalogInput, context.Canceled), 1},
|
||||
{&config.SessionIdentityError{Source: "session.yml", Field: "session_id", Expected: "one", Actual: "two"}, 2},
|
||||
{fmt.Errorf("request: %w", errors.Join(input, invalid)), 2},
|
||||
{errors.Join(input, operational), 1},
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -23,6 +24,32 @@ func catalogReportForTest(t *testing.T, args []string) *artifactCatalogReport {
|
||||
return &report
|
||||
}
|
||||
|
||||
func TestNativeCatalogValidationErrorsAreUsage(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
data, err := os.ReadFile(pipeline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustWriteTestFile(t, pipeline, string(data)+`scriptorium:
|
||||
artifacts:
|
||||
result:
|
||||
enabled: false
|
||||
output_path: artifacts/result.md
|
||||
depends_on: [missing]
|
||||
`)
|
||||
for _, args := range [][]string{
|
||||
{"artifacts", "list", "--config", pipeline},
|
||||
{"run", "2026-05-03", "--stage", "analyze", "--config", pipeline, "--campaign-file", campaign, "--session-file", session},
|
||||
} {
|
||||
var out, diagnostic bytes.Buffer
|
||||
outcome := Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
var input *config.ArtifactCatalogInputError
|
||||
if outcome.Status != 2 || !errors.As(outcome.Cause, &input) {
|
||||
t.Fatalf("%v: status=%d cause=%v diagnostics=%s", args, outcome.Status, outcome.Cause, &diagnostic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactCatalogCommandWithoutCampaignPreservesDependencies(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipeline := filepath.Join(dir, "pipeline.yml")
|
||||
|
||||
Reference in New Issue
Block a user