From a9cca7a0fd7c7585334ae9e5cdb3f13b20db324a Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 2 Jan 2023 16:51:05 +0200 Subject: [PATCH] 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 --- libs/pq_proto/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/pq_proto/src/lib.rs b/libs/pq_proto/src/lib.rs index 278f044c15..d31a2d51f2 100644 --- a/libs/pq_proto/src/lib.rs +++ b/libs/pq_proto/src/lib.rs @@ -626,6 +626,8 @@ fn read_cstr(buf: &mut Bytes) -> anyhow::Result { 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)?;