From 1703a30dec2695e7a5f1b81c633ac4c63479d9dd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 7 Nov 2022 12:04:38 +0200 Subject: Allow passing fail diag record to diag_buffer::close() --- libbuild2/diagnostics.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'libbuild2/diagnostics.cxx') diff --git a/libbuild2/diagnostics.cxx b/libbuild2/diagnostics.cxx index 01bd43f..9433cd8 100644 --- a/libbuild2/diagnostics.cxx +++ b/libbuild2/diagnostics.cxx @@ -425,12 +425,20 @@ namespace build2 state_ = state::eof; } + // Note: flushing of the diag record may throw. + // + args0 = nullptr; + state_ = state::closed; + if (!buf.empty () || !dr.empty ()) { diag_stream_lock l; if (!buf.empty ()) + { diag_stream->write (buf.data (), static_cast (buf.size ())); + buf.clear (); + } if (!dr.empty ()) dr.flush ([] (const butl::diag_record& r) @@ -438,14 +446,11 @@ namespace build2 // Similar to default_writer(). // *diag_stream << r.os.str () << '\n'; + diag_stream->flush (); }); - - diag_stream->flush (); + else + diag_stream->flush (); } - - buf.clear (); - args0 = nullptr; - state_ = state::closed; } // diag_do(), etc. -- cgit v1.1