diff --git a/kernel/log.cc b/kernel/log.cc index 5390cabc0..8ba20d64d 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -386,13 +386,10 @@ void log_formatted_error(std::string str) log_error_with_prefix("ERROR: ", std::move(str)); } -void log_cmd_error(const char *format, ...) +void log_formatted_cmd_error(std::string str) { - va_list ap; - va_start(ap, format); - if (log_cmd_error_throw) { - log_last_error = vstringf(format, ap); + log_last_error = str; // Make sure the error message gets through any selective silencing // of log output @@ -402,7 +399,7 @@ void log_cmd_error(const char *format, ...) pop_errfile = true; } - log("ERROR: %s", log_last_error.c_str()); + log("ERROR: %s", log_last_error); log_flush(); if (pop_errfile) @@ -411,7 +408,7 @@ void log_cmd_error(const char *format, ...) throw log_cmd_error_exception(); } - log_formatted_error(vstringf(format, ap)); + log_formatted_error(str); } void log_spacer() diff --git a/kernel/log.h b/kernel/log.h index 036a2aa4d..6bfc0b421 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -124,8 +124,6 @@ extern int log_debug_suppressed; void set_verific_logging(void (*cb)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg)); extern void (*log_verific_callback)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg); -[[noreturn]] void log_cmd_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); - #ifndef NDEBUG static inline bool ys_debug(int n = 0) { if (log_force_debug) return true; log_debug_suppressed += n; return false; } #else @@ -194,6 +192,13 @@ template log_formatted_file_error(filename, lineno, fmt.format(args...)); } +[[noreturn]] void log_formatted_cmd_error(std::string str); +template +[[noreturn]] void log_cmd_error(FmtString...> fmt, Args... args) +{ + log_formatted_cmd_error(fmt.format(args...)); +} + static inline void log_suppressed() { if (log_debug_suppressed && !log_make_debug) { log("\n", log_debug_suppressed);