From 8f4245860a1b2c4c54f6dfca35d5aa65a5c16bab Mon Sep 17 00:00:00 2001 From: Matt Edmonston Date: Tue, 24 Nov 2026 03:22:44 +0000 Subject: [PATCH 1/2] fix: hint the replacement of old flags; test 413 for non-JSON bodies --- CHANGELOG.md | 9 +++++++++ cmd/pdbr/main.go | 1 + cmd/pdbr/request_test.go | 20 ++++++++++++++++++++ docs/upgrading.md | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- internal/config/config.go | 9 +++++++++ test/e2e_errors_test.go | 18 ++++++++++++++++++ 8 files changed, 62 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0342021..0a775b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,15 @@ becomes the release notes of the next tag. ## [Unreleased] +### Fixed + +- A removed or moved 0.x flag (`--server.max_cost`, `--server.tx_end`, + kebab-case plugin flags) names its replacement or the reason it was removed, + as the config keys and environment variables do, instead of a bare + `unknown flag`. +- Tests cover `413 body_too_large` for oversized bodies that are not JSON, + including chunked ones. + ### Documentation - Fix the quickstart (the `Location` and `unknown_column` samples, the diff --git a/cmd/pdbr/main.go b/cmd/pdbr/main.go index ef42e91..b8c5766 100644 --- a/cmd/pdbr/main.go +++ b/cmd/pdbr/main.go @@ -149,6 +149,7 @@ func rootCmd() *cobra.Command { SilenceUsage: true, SilenceErrors: true, } + root.SetFlagErrorFunc(func(_ *cobra.Command, err error) error { return config.ExplainFlagError(err) }) root.PersistentFlags().String("config", "", "path to config file (default: ./pdbr.yaml if present)") root.AddCommand(serveCmd(), requestCmd(), schemaCmd(), configCmd(), pluginsCmd()) return root diff --git a/cmd/pdbr/request_test.go b/cmd/pdbr/request_test.go index c286bce..12ad236 100644 --- a/cmd/pdbr/request_test.go +++ b/cmd/pdbr/request_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "errors" + "io" "os" "path/filepath" "strings" @@ -226,3 +227,22 @@ func TestRequestIdentityLive(t *testing.T) { t.Errorf("--role anonymous --claims user 1 = %s", got) } } + +func TestOldFlagsNameTheirReplacement(t *testing.T) { + for args, want := range map[string]string{ + "serve --server.tx_end=commit": "unknown flag: --server.tx_end: moved to --transactions.end", + "serve --server.max_cost=5": "unknown flag: --server.max_cost: moved to --limits.max_cost", + "serve --plugins.settings.advanced-filters.enabled=1": "moved to --plugins.settings.advanced_filters.enabled", + "serve --rls.enabled=false": "moved to --roles.switch", + "plugins list --transactions.mutations": "removed: every write runs in a transaction", + } { + cmd := rootCmd() + cmd.SetArgs(strings.Fields(args)) + cmd.SetOut(io.Discard) + cmd.SetErr(io.Discard) + err := cmd.Execute() + if err == nil || !strings.Contains(err.Error(), want) { + t.Errorf("%s: err = %v, want %q", args, err, want) + } + } +} diff --git a/docs/upgrading.md b/docs/upgrading.md index 5d374e2..5871cc9 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -183,8 +183,8 @@ Loading a config or environment that uses an old key fails and names the new one (`unknown key server.tx_end: moved to transactions.end`, `unknown environment variable PDBR_SERVER_MAX__COST (server.max_cost): moved to PDBR_LIMITS_MAX__COST`); flags are renamed the same way -(`--server.tx_end` is `--transactions.end`), but an old flag is only rejected -as `unknown flag` without a suggestion: use the table below. +(`--server.tx_end` is `--transactions.end`), and an old flag is rejected with +the same hint (`unknown flag: --server.tx_end: moved to --transactions.end`). - **`server.base_path` defaults to `""`** (was `/api`): the API is mounted at the root, as in PostgREST, so `GET /api/users` is now `GET /users` and diff --git a/go.mod b/go.mod index 04bce76..7bdb6f5 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 - github.com/suprbdev/pdbcore v0.19.0 + github.com/suprbdev/pdbcore v0.19.1-0.20261124031535-0e87b51a0ca0 go.yaml.in/yaml/v3 v3.0.5 golang.org/x/sync v0.23.0 ) diff --git a/go.sum b/go.sum index 27897fa..2f24597 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= -github.com/suprbdev/pdbcore v0.19.0 h1:0j+vkzyt1bKcREPh6OUT9vX69dzL5QMzAAJvd1Ck+KM= -github.com/suprbdev/pdbcore v0.19.0/go.mod h1:loM9g7/i1GhIY4CRmHeAiMucJ57nxTgxN0YNHc7tW7w= +github.com/suprbdev/pdbcore v0.19.1-0.20261124031535-0e87b51a0ca0 h1:6vHvZYjHjeD6DnlcQ30kCpqw2PG0DiCwnjpNmT+hKxk= +github.com/suprbdev/pdbcore v0.19.1-0.20261124031535-0e87b51a0ca0/go.mod h1:loM9g7/i1GhIY4CRmHeAiMucJ57nxTgxN0YNHc7tW7w= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= diff --git a/internal/config/config.go b/internal/config/config.go index 653a2be..4d85ac3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,6 +15,7 @@ import ( "github.com/suprbdev/pdbcore/auth" "github.com/suprbdev/pdbcore/confx" + "github.com/suprbdev/pdbcore/confx/cliflags" "github.com/suprbdev/pdbcore/contrib" "github.com/suprbdev/pdbr/internal/plugins/advancedfilters" @@ -211,6 +212,14 @@ var RemovedKeys = map[string]string{ "plugins.settings.nested_mutations.force_transactions": "nested writes always run in a transaction", } +// ExplainFlagError adds the moved-to or removed hint to the error of an +// unknown flag that names an old config key (--server.tx_end), as loading +// the key from a file or PDBR_* variable does. +func ExplainFlagError(err error) error { + cfg := DefaultConfig() + return cliflags.Explain(err, &cfg, confx.WithMoved(MovedKeys), confx.WithRemoved(RemovedKeys)) +} + // Load builds the effective config: defaults, then the optional YAML file, // then PDBR_* env vars, then flags (highest precedence: koanf path to // value, see confx.WithFlags), and validates it. Pass only the flags the diff --git a/test/e2e_errors_test.go b/test/e2e_errors_test.go index ba5a0a4..c79c919 100644 --- a/test/e2e_errors_test.go +++ b/test/e2e_errors_test.go @@ -3,6 +3,7 @@ package e2e import ( "context" "errors" + "io" "net/http" "net/http/httptest" "os" @@ -223,6 +224,23 @@ func TestErrorCodesNeedingConfig(t *testing.T) { big := `{"email":"` + strings.Repeat("x", 100) + `"}` runRows(t, srv, []errorRow{ {name: "content-length", method: "POST", path: "/api/users", body: big, status: 413, code: "body_too_large"}, + {name: "not JSON", method: "POST", path: "/api/users", body: strings.Repeat("x", 100), hdr: map[string]string{"Content-Type": "application/json"}, status: 413, code: "body_too_large"}, + {name: "not JSON text/plain", method: "POST", path: "/api/users", body: strings.Repeat("x", 100), hdr: map[string]string{"Content-Type": "text/plain"}, status: 413, code: "body_too_large"}, + {name: "not JSON rpc", method: "POST", path: "/api/rpc/add_numbers", body: strings.Repeat("x", 100), hdr: map[string]string{"Content-Type": "application/json"}, status: 413, code: "body_too_large"}, + }) + t.Run("chunked not JSON", func(t *testing.T) { + req, err := http.NewRequest(http.MethodPost, srv+"/api/users", io.NopCloser(strings.NewReader(strings.Repeat("x", 100)))) + if err != nil { + t.Fatal(err) + } + req.Header.Set("Content-Type", "application/json") + res, err := http.DefaultClient.Do(req) + if err != nil { + t.Fatal(err) + } + defer res.Body.Close() + b, _ := io.ReadAll(res.Body) + wantProblem(t, res, b, 413, "body_too_large") }) }) t.Run("timeout", func(t *testing.T) { From c833735b31ac012d2c8a22f7b067c55f86356ed0 Mon Sep 17 00:00:00 2001 From: Matt Edmonston Date: Tue, 24 Nov 2026 03:30:26 +0000 Subject: [PATCH 2/2] build(deps): pin pdbcore v0.19.1 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7bdb6f5..abbcaa5 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 - github.com/suprbdev/pdbcore v0.19.1-0.20261124031535-0e87b51a0ca0 + github.com/suprbdev/pdbcore v0.19.1 go.yaml.in/yaml/v3 v3.0.5 golang.org/x/sync v0.23.0 ) diff --git a/go.sum b/go.sum index 2f24597..f076c03 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= -github.com/suprbdev/pdbcore v0.19.1-0.20261124031535-0e87b51a0ca0 h1:6vHvZYjHjeD6DnlcQ30kCpqw2PG0DiCwnjpNmT+hKxk= -github.com/suprbdev/pdbcore v0.19.1-0.20261124031535-0e87b51a0ca0/go.mod h1:loM9g7/i1GhIY4CRmHeAiMucJ57nxTgxN0YNHc7tW7w= +github.com/suprbdev/pdbcore v0.19.1 h1:vTl8odNVm2Gi5nU+hsDr4rvY22cozzz0cKLPRp758dg= +github.com/suprbdev/pdbcore v0.19.1/go.mod h1:loM9g7/i1GhIY4CRmHeAiMucJ57nxTgxN0YNHc7tW7w= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=