From 9de41fac7533176cb0e245675e5cb8683d3f1826 Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Wed, 17 May 2023 13:21:46 -0400 Subject: [PATCH] ParseConfig: default_query_exec_mode: Return arg in error If the default_query_exec_mode is unknown, the returned error previously was: invalid default_query_exec_mode: This changes it to return the argument. Add a test that unknown modes fail to parse and include this string. --- conn.go | 2 +- conn_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 46711f82e..cdbd9027a 100644 --- a/conn.go +++ b/conn.go @@ -178,7 +178,7 @@ func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*Con case "simple_protocol": defaultQueryExecMode = QueryExecModeSimpleProtocol default: - return nil, fmt.Errorf("invalid default_query_exec_mode: %v", err) + return nil, fmt.Errorf("invalid default_query_exec_mode: %s", s) } } diff --git a/conn_test.go b/conn_test.go index f1ff2da20..e0b55e813 100644 --- a/conn_test.go +++ b/conn_test.go @@ -197,6 +197,21 @@ func TestParseConfigExtractsDefaultQueryExecMode(t *testing.T) { } } +func TestParseConfigErrors(t *testing.T) { + t.Parallel() + + for _, tt := range []struct { + connString string + expectedErrSubstring string + }{ + {"default_query_exec_mode=does_not_exist", "does_not_exist"}, + } { + config, err := pgx.ParseConfig(tt.connString) + require.Nil(t, config) + require.ErrorContains(t, err, tt.expectedErrSubstring) + } +} + func TestExec(t *testing.T) { t.Parallel()