Skip to content

Commit

Permalink
Add extra info to C Error so Code and SubCode can be deciphered.
Browse files Browse the repository at this point in the history
  • Loading branch information
jurmous committed Dec 29, 2024
1 parent ccfb199 commit 0015f2e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(s.code())) + "|" +
std::to_string(static_cast<unsigned int>(s.subcode())) + "] " +
s.ToString();

*errptr = strdup(combined_error.c_str());
return true;
}

Expand Down

0 comments on commit 0015f2e

Please sign in to comment.