From 920b87f94bcf4d8ab63328ea9c0a98bc852f8273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= Date: Mon, 25 Mar 2024 12:40:15 +0100 Subject: [PATCH] Remove "error:" prefix to SQLite warning message Avoid the confusing error message "warning: error: ..." when SQLite is busy. Instead, just print "warning: ..." as the message. Fixes #6656 --- src/libstore/sqlite.hh | 7 ++++++- src/libutil/error.cc | 6 +++++- src/libutil/logging.cc | 6 ++++++ src/libutil/logging.hh | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libstore/sqlite.hh b/src/libstore/sqlite.hh index 003e4d101..859d56065 100644 --- a/src/libstore/sqlite.hh +++ b/src/libstore/sqlite.hh @@ -158,7 +158,12 @@ protected: }; -MakeError(SQLiteBusy, SQLiteError); +struct SQLiteBusy : SQLiteError +{ + SQLiteBusy(const char *path, const char *errMsg, int errNo, int extendedErrNo, int offset, HintFmt && hf) + : SQLiteError(path, errMsg, errNo, extendedErrNo, offset, std::move(hf)) + { err.level = lvlWarn; } +}; void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning); diff --git a/src/libutil/error.cc b/src/libutil/error.cc index d1e864a1a..24e5244bd 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -25,8 +25,12 @@ void throwExceptionSelfCheck(){ // This stringifies the error and caches it for use by what(), or similarly by msg(). const std::string & BaseError::calcWhat() const { - if (what_.has_value()) + if (what_.has_value()) { + if (err.level == Verbosity::lvlWarn) { + removeErrorPrefix(*what_); + } return *what_; + } else { std::ostringstream oss; showErrorInfo(oss, err, loggerSettings.showTrace); diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 89fbd194a..3a4f6c4ff 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -324,6 +324,12 @@ bool handleJSONLogMessage(const std::string & msg, return handleJSONLogMessage(*json, act, activities, trusted); } +void removeErrorPrefix(std::string & msg) +{ + if (hasPrefix(msg, "error: ")) + msg.erase(0, 7); +} + Activity::~Activity() { try { diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 9e81132e3..b246ab90b 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -257,4 +257,6 @@ inline void warn(const std::string & fs, const Args & ... args) void writeToStderr(std::string_view s); +void removeErrorPrefix(std::string & msg); + }