zblueslip: Show chained causes in unexpected messages.

This commit is contained in:
Alex Vandiver 2023-05-03 20:15:06 +00:00 committed by Tim Abbott
parent fa92895731
commit 5d97dbf8b3
1 changed files with 8 additions and 4 deletions

View File

@ -85,12 +85,12 @@ function make_zblueslip() {
for (const name of names) {
if (!opts[name]) {
// should just log the message.
lib[name] = function (message, more_info, stack) {
lib.test_logs[name].push({message, more_info, stack});
lib[name] = function (message, more_info, cause) {
lib.test_logs[name].push({message, more_info, cause});
};
continue;
}
lib[name] = function (message, more_info, stack) {
lib[name] = function (message, more_info, cause) {
/* istanbul ignore if */
if (typeof message !== "string") {
// We may catch exceptions in blueslip, and if
@ -101,12 +101,16 @@ function make_zblueslip() {
throw new Error("message should be string: " + message);
}
}
lib.test_logs[name].push({message, more_info, stack});
lib.test_logs[name].push({message, more_info, cause});
const matched_error_message = lib.test_data[name].find((x) => x.message === message);
const exact_match_fail = !matched_error_message;
if (exact_match_fail) {
const error = new Error(`Invalid ${name} message: "${message}".`);
error.blueslip = true;
/* istanbul ignore if */
if (cause !== undefined) {
error.cause = cause;
}
throw error;
}
};