Skip to content

Commit

Permalink
non-zero exit code if there are type-errors (#41)
Browse files Browse the repository at this point in the history
Summary:
closes #40

Pull Request resolved: #41

Reviewed By: michalmuskala

Differential Revision: D48784596

Pulled By: ilya-klyuchnikov

fbshipit-source-id: 5507c4545ed09a42fdde148e5d85f6b0010a304c
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed Aug 29, 2023
1 parent 1a787cb commit bf4ea15
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
16 changes: 10 additions & 6 deletions mini-elp/crates/elp/src/bin/eqwalizer_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct EqwalizerInternalArgs<'a> {
strict: bool,
}

pub fn eqwalize_module(args: &Eqwalize, mut out: impl WriteColor) -> Result<()> {
pub fn eqwalize_module(args: &Eqwalize, mut out: impl WriteColor) -> Result<i32> {
let loaded = &match args.project.extension() {
None => {
let profile = args.profile.clone().map(Profile).unwrap_or_default();
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn eqwalize_module(args: &Eqwalize, mut out: impl WriteColor) -> Result<()>
})
}

pub fn eqwalize_all(args: &EqwalizeAll, mut out: impl WriteColor) -> Result<()> {
pub fn eqwalize_all(args: &EqwalizeAll, mut out: impl WriteColor) -> Result<i32> {
let loaded = &match args.project.extension() {
None => {
let profile = args.profile.clone().map(Profile).unwrap_or_default();
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn eqwalize_all(args: &EqwalizeAll, mut out: impl WriteColor) -> Result<()>
})
}

pub fn eqwalize_app(args: &EqwalizeApp, mut out: impl WriteColor) -> Result<()> {
pub fn eqwalize_app(args: &EqwalizeApp, mut out: impl WriteColor) -> Result<i32> {
let loaded = &match args.project.extension() {
None => {
let profile = args.profile.clone().map(Profile).unwrap_or_default();
Expand Down Expand Up @@ -159,7 +159,7 @@ fn eqwalize(
fast,
strict,
}: EqwalizerInternalArgs,
) -> Result<()> {
) -> Result<i32> {
let format = elp_parse_server::Format::OffsetEtf;

if !fast {
Expand All @@ -181,7 +181,11 @@ fn eqwalize(
reporter.write_eqwalizer_diagnostics(file_id, diagnostics)?;
}
reporter.write_error_count()?;
Ok(())
if diagnostics_by_module.is_empty() {
Ok(0)
} else {
Ok(1)
}
}
EqwalizerDiagnostics::NoAst { module } => {
if let Some(file_id) = analysis.module_file_id(loaded.project_id, module) {
Expand All @@ -190,7 +194,7 @@ fn eqwalize(
// The cached parse errors must be non-empty otherwise we wouldn't have `NoAst`
assert!(!parse_diagnostics.is_empty());
reporter.write_parse_diagnostics(&parse_diagnostics)?;
Ok(())
Ok(1)
} else {
bail!(
"Could not type-check because module {} was not found",
Expand Down
41 changes: 23 additions & 18 deletions mini-elp/crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,41 @@ fn main() {
process::exit(code);
}

fn handle_res(result: Result<()>, stderr: &mut impl std::io::Write) -> i32 {
if let Err(err) = result {
writeln!(stderr, "{:#}", err).unwrap();
101
} else {
0
fn handle_res(result: Result<i32>, stderr: &mut impl std::io::Write) -> i32 {
match result {
Ok(code) => code,
Err(err) => {
writeln!(stderr, "{:#}", err).unwrap();
101
}
}
}

fn try_main(
out: &mut impl WriteColor,
err: &mut impl std::io::Write,
os_args: Vec<OsString>,
) -> Result<()> {
) -> Result<i32> {
let args = args::Args::parse(os_args)?;

match args.command {
let exit_code = match args.command {
args::Command::ParseAll(args) => parse_server_cli::parse_all(&args, out)?,
args::Command::Eqwalize(args) => eqwalizer_cli::eqwalize_module(&args, out)?,
args::Command::EqwalizeAll(args) => eqwalizer_cli::eqwalize_all(&args, out)?,
args::Command::EqwalizeApp(args) => eqwalizer_cli::eqwalize_app(&args, out)?,
args::Command::Version => {
writeln!(out, "elp {}", env!("CARGO_PKG_VERSION"))?;
0
}
args::Command::Help => {
writeln!(err, "{}", args::HELP)?;
0
}
}
};

log::logger().flush();

Ok(())
Ok(exit_code)
}

// To run the tests
Expand Down Expand Up @@ -152,14 +155,14 @@ mod tests {

let (stdout, stderr, code) = elp(args_vec!["eqwalize", "--project", project_path, module]);
match code {
0 => {
expected.assert_eq(&stdout);
assert!(stderr.is_empty())
}
_ => {
101 => {
expected.assert_eq(&stderr);
assert!(stdout.is_empty());
}
_ => {
expected.assert_eq(&stdout);
assert!(stderr.is_empty())
}
}
Ok(())
}
Expand Down Expand Up @@ -293,10 +296,12 @@ mod tests {
};
let args = [args, args_vec!["--project", project_path]].concat();
let (stdout, stderr, code) = elp(args);
assert_eq!(
code, 0,
assert!(
code != 101,
"failed with exit code: {}\nstdout:\n{}\nstderr:\n{}",
code, stdout, stderr
code,
stdout,
stderr
);
expected.assert_eq(&stdout);
assert!(
Expand Down
4 changes: 2 additions & 2 deletions mini-elp/crates/elp/src/bin/parse_server_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::reporting;
use crate::reporting::ParseDiagnostic;
use crate::util;

pub fn parse_all(args: &ParseAll, out: &mut impl std::io::Write) -> Result<()> {
pub fn parse_all(args: &ParseAll, out: &mut impl std::io::Write) -> Result<i32> {
let profile = args.profile.clone().map(Profile).unwrap_or_default();
let loaded = load_rebar::load_project_at(&args.project, &profile)?;
fs::create_dir_all(&args.to)?;
Expand All @@ -46,7 +46,7 @@ pub fn parse_all(args: &ParseAll, out: &mut impl std::io::Write) -> Result<()> {
)
.unwrap();
}
Ok(())
Ok(0)
}

pub fn do_parse_all(
Expand Down

0 comments on commit bf4ea15

Please sign in to comment.