From fe469a5455c59fc0dd9098fe45f78de75b02486a Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Tue, 2 Jun 2026 10:19:02 +0200 Subject: [PATCH] Guard against assert() failures in SendJsonError() Co-authored-by: Julian Brost --- lib/remote/httputility.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/remote/httputility.cpp b/lib/remote/httputility.cpp index 5e466bb8a..f868dae81 100644 --- a/lib/remote/httputility.cpp +++ b/lib/remote/httputility.cpp @@ -86,6 +86,16 @@ void HttpUtility::SendJsonBody(HttpApiResponse& response, const Dictionary::Ptr& void HttpUtility::SendJsonError(HttpApiResponse& response, const Dictionary::Ptr& params, int code, const String& info, const String& diagnosticInformation) { + if (response.HasSerializationStarted()) { + std::ostringstream err; + err << "Impossible to send error response after streaming has started: error: '" << code << "', status: '" + << info << "'"; + if (!diagnosticInformation.IsEmpty()) { + err << ", diagnostic_information: '" << diagnosticInformation << "'"; + } + BOOST_THROW_EXCEPTION(std::logic_error{err.str()}); + } + Dictionary::Ptr result = new Dictionary({ { "error", code } }); if (!info.IsEmpty()) {