Skip to content

Commit

Permalink
Add missing_output_as_error to DriverDef (#1237)
Browse files Browse the repository at this point in the history
Related to #1223
  • Loading branch information
marschattha authored Dec 2, 2024
1 parent 2bd4ca8 commit 72d7594
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 8 deletions.
26 changes: 18 additions & 8 deletions qlty-check/src/executor/invocation_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down Expand Up @@ -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());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.qlty/results
.qlty/logs
.qlty/out
.qlty/sources
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions qlty-cli/tests/cmd/check/missing_output_as_error.in/sample.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "hi"
3 changes: 3 additions & 0 deletions qlty-cli/tests/cmd/check/missing_output_as_error.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[0/1] [..]Planning... [..]s
[1/1] [..]Analyzing all targets...[..]
❌ Lint error
4 changes: 4 additions & 0 deletions qlty-cli/tests/cmd/check/missing_output_as_error.stdout
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions qlty-cli/tests/cmd/check/missing_output_as_error.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin.name = "qlty"
args = ["check", "--all", "--no-cache"]
status.code = 3
3 changes: 3 additions & 0 deletions qlty-config/src/config/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ pub struct DriverDef {

#[serde(default)]
pub autoload_script: Option<String>,

#[serde(default)]
pub missing_output_as_error: bool,
}

fn default_driver_timeout() -> u64 {
Expand Down

0 comments on commit 72d7594

Please sign in to comment.