Skip to content

Commit

Permalink
fix: print error: messages and their contents from cargo (#3336)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkelleyrtp authored Dec 11, 2024
1 parent 49caa2b commit 94a499c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 4 additions & 0 deletions packages/cli/src/build/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand Down
26 changes: 20 additions & 6 deletions packages/cli/src/build/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/serve/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 94a499c

Please sign in to comment.