See only top few compilation errors



Sometimes when I change the interface on some of the functions, I need to update a good amount of code with huge number of compilation errors.

It would be much easier to see just top (not bottom) few errors to avoid being overwhelmed.

So I tried cargo build | head but it looks like cargo doesn’t write to a normal stdout so that doesn’t work (also cargo build > x.txt || cat x.txt returns an empty file).

How can I just see the top few errors?



Cargo sends output to stderr, so something like this should work:

cargo build 2>&1 | head -n 20


Ahh, makes sense :mask:. Thanks!

Just need to figure out how to preserve the colours now :slight_smile:


Oh, sure, just tell Cargo you want to force colored output despite the running context:

cargo build --color=always 2>&1 | head -n 20


Yeah, found the --color option. Thanks :thumbsup:


cargo test --color=always 2>&1 | head -n 20 unfortunately doesn’t preserve the colorisation of the test results (ok/FAILED).


I think it’s a cargo issue. Filed one.


Though a bit ugly, the command should look like this:

cargo test --color=always -- --color=always 2>&1 | head -n 20