From 3ea87a1d2822bc4daf6a5dbfd0a31fd878190033 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 14 Jul 2022 15:36:53 +0200 Subject: [PATCH] Util: Print Json error messages to stderr --- src/util/json/job.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/util/json/job.cpp b/src/util/json/job.cpp index 5e1a60b..efa4aef 100644 --- a/src/util/json/job.cpp +++ b/src/util/json/job.cpp @@ -61,10 +61,11 @@ void Job::printErrorLine(Token token, const char* message) "\033[0m" // Reset "%s" "\n"; - printf(errorFormat.c_str(), - token.line + 1, - token.column + 1, - message); + fprintf(stderr, + errorFormat.c_str(), + token.line + 1, + token.column + 1, + message); // Get the JSON line that caused the error std::istringstream input(m_input); @@ -91,10 +92,11 @@ void Job::printErrorLine(Token token, const char* message) "%s" "\033[0m" // Reset "\n"; - printf(lineFormat.c_str(), - token.line + 1, - line.substr(0, token.column).c_str(), - line.substr(token.column).c_str()); + fprintf(stderr, + lineFormat.c_str(), + token.line + 1, + line.substr(0, token.column).c_str(), + line.substr(token.column).c_str()); // Arrow pointer std::string arrowFormat = " %s | " @@ -102,10 +104,11 @@ void Job::printErrorLine(Token token, const char* message) "%s^%s" "\033[0m" // Reset "\n"; - printf(arrowFormat.c_str(), - std::string(m_lineNumbersWidth, ' ').c_str(), - std::string(token.column, ' ').c_str(), - std::string(line.length() - token.column, '~').c_str()); + fprintf(stderr, + arrowFormat.c_str(), + std::string(m_lineNumbersWidth, ' ').c_str(), + std::string(token.column, ' ').c_str(), + std::string(line.length() - token.column, '~').c_str()); } } // namespace Json