aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/diagnostics.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-11-07 12:04:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-11-08 11:08:03 +0200
commit1703a30dec2695e7a5f1b81c633ac4c63479d9dd (patch)
tree48168a64b070f7e24384cce1ea2b4cc61d875602 /libbuild2/diagnostics.cxx
parent5efc7faaea8fc780cf0fc9d0629fc50ea4fbd3b4 (diff)
Allow passing fail diag record to diag_buffer::close()
Diffstat (limited to 'libbuild2/diagnostics.cxx')
-rw-r--r--libbuild2/diagnostics.cxx17
1 files changed, 11 insertions, 6 deletions
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<streamsize> (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.