diff --git a/qlty-check/src/executor/invocation_result.rs b/qlty-check/src/executor/invocation_result.rs index b0f4eae9..a6596f3e 100644 --- a/qlty-check/src/executor/invocation_result.rs +++ b/qlty-check/src/executor/invocation_result.rs @@ -276,7 +276,11 @@ impl InvocationResult { self.invocation.tmpfile_contents = Some(contents); } Err(e) => { - self.invocation.parser_error = Some(e.to_string()); + if self.plan.driver.missing_output_as_error { + self.invocation.tmpfile_contents = Some("".to_string()); + } else { + self.invocation.parser_error = Some(e.to_string()); + } } } @@ -323,14 +327,20 @@ impl InvocationResult { &self.invocation.stdout }; - let file_results = self.plan.driver.parse(output, &self.plan); + if output.is_empty() && self.plan.driver.missing_output_as_error { + self.invocation.exit_result = + qlty_types::analysis::v1::ExitResult::UnknownError.into(); + self.log_error_output(); + } else { + let file_results = self.plan.driver.parse(output, &self.plan); - match file_results { - Ok(file_results) => { - self.file_results = Some(file_results); - } - Err(e) => { - self.invocation.parser_error = Some(e.to_string()); + match file_results { + Ok(file_results) => { + self.file_results = Some(file_results); + } + Err(e) => { + self.invocation.parser_error = Some(e.to_string()); + } } } } diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.in/.gitignore b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.gitignore new file mode 100644 index 00000000..abbd1c70 --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.gitignore @@ -0,0 +1,4 @@ +.qlty/results +.qlty/logs +.qlty/out +.qlty/sources diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.in/.qlty/qlty.toml b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.qlty/qlty.toml new file mode 100644 index 00000000..16e0dc0b --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.in/.qlty/qlty.toml @@ -0,0 +1,15 @@ +config_version = "0" + +[plugins.definitions.exists] +file_types = ["shell"] + +[plugins.definitions.exists.drivers.lint] +prepare_script = "mkdir ${linter} && echo dir %2 > ${linter}/ls.cmd" +script = "echo \"The plugin crashed for some reason\"" +success_codes = [0] +output = "tmpfile" +missing_output_as_error = true + +[[plugin]] +name = "exists" +version = "1.0.0" diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh b/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh new file mode 100644 index 00000000..279508d8 --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "hi" diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.stderr b/qlty-cli/tests/cmd/check/missing_output_as_error.stderr new file mode 100644 index 00000000..fb45509f --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.stderr @@ -0,0 +1,3 @@ + [0/1] [..]Planning... [..]s + [1/1] [..]Analyzing all targets...[..] +❌ Lint error diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.stdout b/qlty-cli/tests/cmd/check/missing_output_as_error.stdout new file mode 100644 index 00000000..a568d64f --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.stdout @@ -0,0 +1,4 @@ +Lint error exists: Exited with code 0 .qlty/out/invocations/invoke-[..].yaml +[..]The plugin crashed for some reason[..] + +Checked 1 files diff --git a/qlty-cli/tests/cmd/check/missing_output_as_error.toml b/qlty-cli/tests/cmd/check/missing_output_as_error.toml new file mode 100644 index 00000000..1e5615cb --- /dev/null +++ b/qlty-cli/tests/cmd/check/missing_output_as_error.toml @@ -0,0 +1,3 @@ +bin.name = "qlty" +args = ["check", "--all", "--no-cache"] +status.code = 3 diff --git a/qlty-config/src/config/plugin.rs b/qlty-config/src/config/plugin.rs index 6c0bddc6..4a87374d 100644 --- a/qlty-config/src/config/plugin.rs +++ b/qlty-config/src/config/plugin.rs @@ -110,6 +110,9 @@ pub struct DriverDef { #[serde(default)] pub autoload_script: Option, + + #[serde(default)] + pub missing_output_as_error: bool, } fn default_driver_timeout() -> u64 {