See only top few compilation errors


#1

Hi,

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?

Thanks.


#2

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

cargo build 2>&1 | head -n 20

#3

Ahh, makes sense :mask:. Thanks!

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


#4

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

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

#5

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


#6

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


#7

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


#8

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

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