Skip to content

return non-zero exit code if there are errors #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2016

Conversation

matklad
Copy link
Member

@matklad matklad commented Apr 13, 2016

closes #150

@nrc please review

fn new() -> FormatReport {
FormatReport { file_error_map: HashMap::new() }
}

pub fn warning_count(&self) -> usize {
self.file_error_map.iter().map(|(_, ref errors)| errors.len()).fold(0, |acc, x| acc + x)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am keen to rename warning_count -> error_count.

@nrc
Copy link
Member

nrc commented Apr 13, 2016

The code looks good, however, I think it is important to distinguish between formatting errors, parsing errors, and errors in operation, and return different codes. I.e., the caller should be able to distinguish between an error like can't open a file and a formatting error like producing an over-long line.

And you should document this somewhere (in the README, I guess).

@matklad
Copy link
Member Author

matklad commented Apr 15, 2016

@nrc this now returns 1, 2, or 3 depending on what exactly has failed. I'm not sure what exact numbers should we use here. Maybe it is safer to leave 1 to misc errors, and use 102, 103 for "can't parse", "can't format" situations?

@nrc
Copy link
Member

nrc commented Apr 15, 2016

looks good, thanks for the changes.

I think 1, 2, 3 is OK for now, we can change them later. We should reconfirm that they are right before 1.0.

@nrc nrc merged commit e1d33df into rust-lang:master Apr 15, 2016
@jonhoo
Copy link
Contributor

jonhoo commented Apr 15, 2016

This interacts pretty poorly with rust.vim, which will bail out by not saving and printing out the entire file contents in the terminal when rustfmt exist with a non-zero return code (see rust-lang/rust.vim#75).

@matklad
Copy link
Member Author

matklad commented Apr 15, 2016

rustfmt exits with non zero for a reason. It means that it was unable to format everything correctly (and syntax errors prevent formatting). Can rust.vim be changed so that it reports rustfmt failures more subtly?

@jonhoo
Copy link
Contributor

jonhoo commented Apr 15, 2016

@matklad: I agree, the correct thing for rustfmt to do is to indicate that it encountered problems. When the problems are terminal (i.e., nothing could be done), then the right thing to do is definitely to exit with an error code. When the problems are really warnings (e.g., one line couldn't be formatted as it was too long, but otherwise formatting completed), I'm not sure that is the right behavior. That said, this is definitely a bug in rust.vim (which is why it's been filed). The temporary workaround is to set g:rustfmt_fail_silently = 1.

fnichol added a commit to fnichol/rust.vim that referenced this pull request May 31, 2016
This change updates the acceptable exit codes from `rustfmt` when
deciding whether or not to write back the file or display the errors
location list.

As of rust-lang/rustfmt#923, `rustfmt` exits with either a 0, 1,
2, or 3 depending on what happened. Prior to this upstream change,
`rustfmt` would exit 0 when issues that cannot be automatically resolved
would occur. Now, the same errors (such as "line exceeded maximum
length") result in an exit of 3 (see the [README](line exceeded maximum
length) for more details).

This change will treat an exit of 3 as "okay" for writing back as
`rustfmt` didn't fail (it just couldn't auto-format a nicer solution).

Closes rust-lang#68
Closes rust-lang#75
References rust-lang/rustfmt#923
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set the exit code
3 participants