From 83233d24d36bed1ebeb4f45f235bda6e168ac6cd Mon Sep 17 00:00:00 2001 From: avison9 Date: Sat, 14 Nov 2026 11:51:50 +0100 Subject: [PATCH] An unknown --fail-on value is an error instead of quietly meaning error `--fail-on warnings` (or WARNING, or err) used to fall through to the default, error: a pipeline that asked to block on warnings let them pass and believed it was guarded. cdclint now exits 2 before reading anything, names the value and lists error, warning, info, as --disable already does for an unknown rule. The GitHub Action passed its input through unchanged, and an empty input (a workflow templating an unset variable) used to mean error. It still does: action.yml substitutes error for an empty input, so only a value that names no severity fails the step. Rejected: accepting other spellings (warnings, WARNING). A gate's threshold is worth spelling exactly; an alias table is one more thing to document, and the error message says what to write. --- README.md | 3 ++- action.yml | 5 ++++- cmd/cdclint/main.go | 16 +++++++++------- cmd/cdclint/main_test.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index adf5d73..d876691 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,8 @@ to keep the column out of the inventory afterwards too, name both rules: `-- cdclint:ignore schema-before-connector,source-column-not-captured: PII`. Files in, findings out, non-zero exit. No database, no daemon, no credentials. -Under a second on a laptop. `--fail-on warning` or `info` raises the bar; +Under a second on a laptop. `--fail-on warning` or `info` raises the bar +(any other value is an error, not the default); `--format json` is for anything that wants to post findings somewhere. A later live mode reads the deployed Postgres, Kafka Connect and sink to report drift against what is actually running. diff --git a/action.yml b/action.yml index f7cd0cf..743cc2c 100644 --- a/action.yml +++ b/action.yml @@ -133,7 +133,10 @@ runs: PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} run: | set -uo pipefail - args=(--migrations "$MIGRATIONS" --connector "$CONNECTOR" --fail-on "$FAIL_ON") + # An empty input (a workflow passing an unset variable) meant error + # before cdclint checked --fail-on, and still does; anything else + # that is not error, warning or info now fails the step. + args=(--migrations "$MIGRATIONS" --connector "$CONNECTOR" --fail-on "${FAIL_ON:-error}") if [ -n "$DISABLE" ]; then args+=(--disable "$DISABLE") fi diff --git a/cmd/cdclint/main.go b/cmd/cdclint/main.go index 054459c..14aca0b 100644 --- a/cmd/cdclint/main.go +++ b/cmd/cdclint/main.go @@ -70,6 +70,15 @@ func run(args []string, stdout, stderr io.Writer) int { fmt.Fprintln(stdout, "cdclint", version) return 0 } + // An unknown --fail-on used to fall through to error, so + // `--fail-on warnings` let warnings pass while the pipeline believed it + // blocked on them. It is checked before anything is read, like + // --disable, so a typo cannot look like a clean run. + threshold, ok := map[string]model.Severity{"error": model.Error, "warning": model.Warning, "info": model.Info}[*minSev] + if !ok { + fmt.Fprintf(stderr, "cdclint: --fail-on: unknown severity %q; the severities are error, warning, info\n", *minSev) + return 2 + } disabled := map[string]bool{} for _, v := range disable { for _, name := range strings.Split(v, ",") { @@ -139,13 +148,6 @@ func run(args []string, stdout, stderr io.Writer) int { default: fmt.Fprint(stdout, TextReport(findings, hidden, acked)) } - threshold := model.Error - switch *minSev { - case "warning": - threshold = model.Warning - case "info": - threshold = model.Info - } for _, f := range findings { if f.Severity >= threshold { return 1 diff --git a/cmd/cdclint/main_test.go b/cmd/cdclint/main_test.go index d7055b3..fdda858 100644 --- a/cmd/cdclint/main_test.go +++ b/cmd/cdclint/main_test.go @@ -88,3 +88,32 @@ func TestJSONKeepsItsShapeAndNotesOnStderr(t *testing.T) { t.Errorf("stderr %q", errOut) } } + +func TestAnUnknownFailOnIsAnErrorNotTheDefault(t *testing.T) { + // "warnings" used to fall through to the default, error: a pipeline + // that asked to block on warnings passed them silently. include-list-typo + // has a warning and an error, so any lint that ran would exit 1. + // An explicit empty value is rejected too; action.yml maps an empty + // input to error itself, so only the CLI sees "" from a person. + for _, bad := range []string{"warnings", "WARNING", "err", ""} { + code, out, errOut := cli(t, append(entry("include-list-typo"), "--fail-on", bad)...) + if code != 2 || out != "" { + t.Errorf("--fail-on %q: exit %d, stdout %q; want exit 2 before linting", bad, code, out) + } + if !strings.Contains(errOut, "--fail-on") || !strings.Contains(errOut, "error, warning, info") { + t.Errorf("--fail-on %q: stderr %q", bad, errOut) + } + } + // The three that exist still work; info and warning reach the warning. + for sev, want := range map[string]int{"error": 1, "warning": 1, "info": 1} { + if code, _, _ := cli(t, append(entry("include-list-typo"), "--fail-on", sev)...); code != want { + t.Errorf("--fail-on %s: exit %d, want %d", sev, code, want) + } + } + if code, _, _ := cli(t, append(entry("include-list-typo"), "--fail-on", "warning", "--disable", "sink-column-not-captured")...); code != 1 { + t.Errorf("--fail-on warning with only the warning left: exit %d, want 1", code) + } + if code, _, _ := cli(t, append(entry("include-list-typo"), "--disable", "sink-column-not-captured")...); code != 0 { + t.Errorf("default --fail-on error with only the warning left: exit %d, want 0", code) + } +}