Use proper error code for BeMessage error responses (#3240)

Based on
https://github.com/neondatabase/neon/pull/3227#discussion_r1059430067

Seems that the constant, used for internal error during BeMessage error
response serialization is incorrect.
Currently used one is `CXX000`, yet all docs mention `XX000` instead:

* https://www.postgresql.org/docs/current/errcodes-appendix.html
* https://docs.rs/postgres/latest/postgres/error/struct.SqlState.html#associatedconstant.INTERNAL_ERROR

I have checked it with the patch and logs described in
https://github.com/neondatabase/neon/pull/3227#discussion_r1059949982
This commit is contained in:
Kirill Bulatov
2023-01-02 16:51:05 +02:00
committed by GitHub
parent 6fd64cd5f6
commit a9cca7a0fd

View File

@@ -626,6 +626,8 @@ fn read_cstr(buf: &mut Bytes) -> anyhow::Result<Bytes> {
Ok(result)
}
const SQLSTATE_INTERNAL_ERROR: &str = "XX000\0";
impl<'a> BeMessage<'a> {
/// Write message to the given buf.
// Unlike the reading side, we use BytesMut
@@ -776,7 +778,7 @@ impl<'a> BeMessage<'a> {
buf.put_slice(b"ERROR\0");
buf.put_u8(b'C'); // SQLSTATE error code
buf.put_slice(b"CXX000\0");
buf.put_slice(SQLSTATE_INTERNAL_ERROR.as_bytes());
buf.put_u8(b'M'); // the message
write_cstr(error_msg, buf)?;
@@ -799,7 +801,7 @@ impl<'a> BeMessage<'a> {
buf.put_slice(b"NOTICE\0");
buf.put_u8(b'C'); // SQLSTATE error code
buf.put_slice(b"CXX000\0");
buf.put_slice(SQLSTATE_INTERNAL_ERROR.as_bytes());
buf.put_u8(b'M'); // the message
write_cstr(error_msg.as_bytes(), buf)?;