add: config client-error-verbosity to set error verbosity

Set error verbosity using this config. The verbosity can
be set to `verbose` or `minimal` for client error responses.

This only affects client side HTTP responses, server side logs
are not affected by this config.

Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
Taimoor Zaeem
2026-02-25 15:24:27 -05:00
committed by Steve Chavez
parent 2edc44c352
commit 83dc082acf
29 changed files with 179 additions and 38 deletions
+1
View File
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
+1
View File
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
@@ -1,3 +1,4 @@
client-error-verbosity = "minimal"
db-aggregates-enabled = false
db-anon-role = "pre_config_role"
db-channel = "postgrest"
@@ -1,3 +1,4 @@
client-error-verbosity = "minimal"
db-aggregates-enabled = false
db-anon-role = "anonymous"
db-channel = "postgrest"
@@ -1,3 +1,4 @@
client-error-verbosity = "minimal"
db-aggregates-enabled = true
db-anon-role = "root"
db-channel = "postgrest"
+1
View File
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
+1
View File
@@ -1,3 +1,4 @@
client-error-verbosity = "verbose"
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
+1
View File
@@ -1,5 +1,6 @@
PGRST_APP_SETTINGS_test2: test
PGRST_APP_SETTINGS_test: test
PGRST_CLIENT_ERROR_VERBOSITY: minimal
PGRST_DB_AGGREGATES_ENABLED: true
PGRST_DB_ANON_ROLE: root
PGRST_DB_CHANNEL: postgrest
+1
View File
@@ -1,3 +1,4 @@
client-error-verbosity = "minimal"
db-aggregates-enabled = true
db-anon-role = "root"
db-channel = "postgrest"
+2
View File
@@ -2,6 +2,7 @@ CREATE ROLE db_config_authenticator LOGIN NOINHERIT;
-- reloadable config options
-- these settings will override the values in configs/no-defaults.config, so they must be different
ALTER ROLE db_config_authenticator SET pgrst.client_error_verbosity = 'minimal';
ALTER ROLE db_config_authenticator SET pgrst.db_aggregates_enabled = 'false';
ALTER ROLE db_config_authenticator SET pgrst.db_anon_role = 'anonymous';
ALTER ROLE db_config_authenticator SET pgrst.db_extra_search_path = 'public, extensions';
@@ -56,6 +57,7 @@ ALTER ROLE db_config_authenticator SET pgrst.server_unix_socket_mode = 'ignored'
-- other authenticator reloadable config options
-- these settings will override the values in configs/no-defaults.config, so they must be different
CREATE ROLE other_authenticator LOGIN NOINHERIT;
ALTER ROLE other_authenticator SET pgrst.client_error_verbosity = 'minimal';
ALTER ROLE other_authenticator SET pgrst.db_aggregates_enabled = 'false';
ALTER ROLE other_authenticator SET pgrst.db_extra_search_path = 'public, extensions, other';
ALTER ROLE other_authenticator SET pgrst.db_max_rows = '100';
+11
View File
@@ -286,6 +286,17 @@ def test_jwt_secret_min_length(defaultenv):
assert "The JWT secret must be at least 32 characters long." in error
def test_invalid_client_error_verbosity(defaultenv):
"Given an invalid value for client-error-verbosity, Postgrest should exit with a non-zero exit code."
env = {
**defaultenv,
"PGRST_CLIENT_ERROR_VERBOSITY": "invalid",
}
error = cli(["--dump-config"], env=env, expect_error=True)
assert "Invalid client-error-verbosity. Check your configuration." in error
@pytest.mark.parametrize("restricted_schema", FIXTURES["restrictedschemas"])
def test_restricted_db_schemas(restricted_schema, defaultenv):
"Should print error when db-schemas config contain pg_catalog or information_schema"
+32
View File
@@ -1757,3 +1757,35 @@ def test_server_timing_transaction_duration(defaultenv, metapostgrest):
]
assert 2000 <= response_dur < 3000
def test_client_error_verbosity_config(defaultenv):
"Test PostgREST errors with different error verbosity settings"
env = {
**defaultenv,
"PGRST_CLIENT_ERROR_VERBOSITY": "minimal", # hide details and hint
}
with run(env=env) as postgrest:
response = postgrest.session.get("/itemsxx")
assert response.status_code == 404
assert response.json() == {
"code": "PGRST205",
"message": "Could not find the table 'public.itemsxx' in the schema cache",
}
env = {
**defaultenv,
"PGRST_CLIENT_ERROR_VERBOSITY": "verbose",
}
with run(env=env) as postgrest:
response = postgrest.session.get("/itemsxx")
assert response.status_code == 404
assert response.json() == {
"code": "PGRST205",
"message": "Could not find the table 'public.itemsxx' in the schema cache",
"details": None,
"hint": "Perhaps you meant the table 'public.items'",
}
+2 -1
View File
@@ -40,7 +40,7 @@ import PostgREST.Config (AppConfig (..),
JSPathExp (..),
LogLevel (..),
OpenAPIMode (..),
parseSecret)
Verbosity (..), parseSecret)
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
import Prometheus (Counter, getCounter)
import Protolude hiding (get, toS)
@@ -121,6 +121,7 @@ baseCfg :: AppConfig
baseCfg = let secret = encodeUtf8 "reallyreallyreallyreallyverysafe" in
AppConfig {
configAppSettings = [ ("app.settings.app_host", "localhost") , ("app.settings.external_api_secret", "0123456789abcdef") ]
, configClientErrorVerbosity = Verbose
, configDbAggregates = False
, configDbAnonRole = Just "postgrest_test_anonymous"
, configDbChannel = mempty