Skip to content

Commit

Permalink
ParseConfig: default_query_exec_mode: Return arg in error
Browse files Browse the repository at this point in the history
If the default_query_exec_mode is unknown, the returned error
previously was:

    invalid default_query_exec_mode: <nil>

This changes it to return the argument. Add a test that unknown modes
fail to parse and include this string.
  • Loading branch information
evanj authored and jackc committed May 20, 2023
1 parent 11d892d commit 9de41fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
15 changes: 15 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 9de41fa

Please sign in to comment.