Skip to content

Commit

Permalink
Update methods and (safely) ignore errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Mar 5, 2024
1 parent 5fe1fd8 commit f7f9fad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion databases/postgres/query_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ func testQueryRequest() (string, string) {
query := "SELECT * FROM users"
queryMsg := pgproto3.Query{String: query}
// Encode the data to base64.
return query, base64.StdEncoding.EncodeToString(queryMsg.Encode(nil))
queryBytes, _ := queryMsg.Encode(nil)
return query, base64.StdEncoding.EncodeToString(queryBytes)
}

func Test_GetQueryFromRequest(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion databases/postgres/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ func IsPostgresStartupMessage(b []byte) bool {
}

func ErrorResponse(msg, severity, code, detail string) []byte {
return (&pgproto3.ErrorResponse{
// NOTE: The error from the Encode method can be safely ignored because
// the result will be nil on error. The parameters MUST be provided by us
// and they MUST NOT be filled with user input.
errResp, _ := (&pgproto3.ErrorResponse{
Severity: severity,
Message: msg,
Code: code,
Detail: detail,
}).Encode(nil)
return errResp
}

// IsPostgresSSLRequest returns true if the message is a SSL request.
Expand Down

0 comments on commit f7f9fad

Please sign in to comment.