fix: print error: messages and their contents from cargo (#3336)
This commit is contained in:
1 parent
49caa2b113
commit
94a499c900
3 files changed
+25
-12
No files matched your search
@@ -41,6 +41,10 @@ impl BuildRequest {
|
||||
.unbounded_send(BuildUpdate::CompilerMessage { message });
|
||||
}
|
||||
|
||||
pub(crate) fn status_build_error(&self, line: String) {
|
||||
tracing::error!(dx_src = ?TraceSrc::Cargo, "{line}");
|
||||
}
|
||||
|
||||
pub(crate) fn status_build_message(&self, line: String) {
|
||||
tracing::trace!(dx_src = ?TraceSrc::Cargo, "{line}");
|
||||
}
|
||||
|
||||
@@ -163,6 +163,7 @@ impl BuildRequest {
|
||||
let mut stdout = stdout.lines();
|
||||
let mut stderr = stderr.lines();
|
||||
let mut units_compiled = 0;
|
||||
let mut emitting_error = false;
|
||||
|
||||
loop {
|
||||
use cargo_metadata::Message;
|
||||
@@ -173,15 +174,28 @@ impl BuildRequest {
|
||||
else => break,
|
||||
};
|
||||
|
||||
let mut deserializer = serde_json::Deserializer::from_str(line.trim());
|
||||
deserializer.disable_recursion_limit();
|
||||
|
||||
let message =
|
||||
Message::deserialize(&mut deserializer).unwrap_or(Message::TextLine(line));
|
||||
let message = Message::parse_stream(std::io::Cursor::new(line))
|
||||
.next()
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
match message {
|
||||
Message::BuildScriptExecuted(_) => units_compiled += 1,
|
||||
Message::TextLine(line) => self.status_build_message(line),
|
||||
Message::TextLine(line) => {
|
||||
// For whatever reason, if there's an error while building, we still receive the TextLine
|
||||
// instead of an "error" message. However, the following messages *also* tend to
|
||||
// be the error message, and don't start with "error:". So we'll check if we've already
|
||||
// emitted an error message and if so, we'll emit all following messages as errors too.
|
||||
if line.trim_start().starts_with("error:") {
|
||||
emitting_error = true;
|
||||
}
|
||||
|
||||
if emitting_error {
|
||||
self.status_build_error(line);
|
||||
} else {
|
||||
self.status_build_message(line)
|
||||
}
|
||||
}
|
||||
Message::CompilerMessage(msg) => self.status_build_diagnostic(msg),
|
||||
Message::CompilerArtifact(artifact) => {
|
||||
units_compiled += 1;
|
||||
|
||||
@@ -265,12 +265,7 @@ impl Output {
|
||||
pub fn push_cargo_log(&mut self, message: cargo_metadata::CompilerMessage) {
|
||||
use cargo_metadata::diagnostic::DiagnosticLevel;
|
||||
|
||||
if self.trace
|
||||
|| matches!(
|
||||
message.message.level,
|
||||
DiagnosticLevel::Error | DiagnosticLevel::FailureNote
|
||||
)
|
||||
{
|
||||
if self.trace || !matches!(message.message.level, DiagnosticLevel::Note) {
|
||||
self.push_log(TraceMsg::cargo(message));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user