From 0015f2eead653926d1a2c2df499dc94d81c8c9fd Mon Sep 17 00:00:00 2001 From: Jurriaan Mous Date: Sun, 29 Dec 2024 15:30:10 +0100 Subject: [PATCH] Add extra info to C Error so Code and SubCode can be deciphered. --- db/c.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/db/c.cc b/db/c.cc index 0858568afef0..06dde26b151d 100644 --- a/db/c.cc +++ b/db/c.cc @@ -572,14 +572,20 @@ static bool SaveError(char** errptr, const Status& s) { assert(errptr != nullptr); if (s.ok()) { return false; - } else if (*errptr == nullptr) { - *errptr = strdup(s.ToString().c_str()); - } else { + } + + if (*errptr != nullptr) { // TODO(sanjay): Merge with existing error? // This is a bug if *errptr is not created by malloc() free(*errptr); - *errptr = strdup(s.ToString().c_str()); } + + std::string combined_error = "[" + + std::to_string(static_cast(s.code())) + "|" + + std::to_string(static_cast(s.subcode())) + "] " + + s.ToString(); + + *errptr = strdup(combined_error.c_str()); return true; }