Skip to content

Commit

Permalink
Revert "Change default behavior for missing output" (#1477)
Browse files Browse the repository at this point in the history
Reverts #1466
  • Loading branch information
brynary authored Feb 5, 2025
1 parent 474e8e6 commit 13ebd82
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 62 deletions.
77 changes: 38 additions & 39 deletions qlty-check/src/executor/invocation_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::{Context, Result};
use chrono::prelude::*;
use qlty_analysis::utils::fs::path_to_string;
use qlty_config::{
config::{OutputDestination, OutputMissing, TargetType},
config::{OutputDestination, TargetType},
version::QLTY_VERSION,
};
use qlty_types::analysis::v1::{
Expand Down Expand Up @@ -273,7 +273,20 @@ impl InvocationResult {
let tmpfile_path = self.invocation.tmpfile_path.as_ref().unwrap();
let read_result = std::fs::read_to_string(tmpfile_path)
.with_context(|| format!("Failed to read tmpfile contents from {}", tmpfile_path));
self.invocation.tmpfile_contents = read_result.ok();

match read_result {
Ok(contents) => {
self.invocation.tmpfile_contents = Some(contents);
}
Err(e) => {
if self.plan.driver.missing_output_as_error {
self.invocation.tmpfile_contents = Some("".to_string());
} else {
self.invocation.parser_error = Some(e.to_string());
}
}
}

Ok(())
}

Expand Down Expand Up @@ -307,51 +320,37 @@ impl InvocationResult {
}

fn handle_output_parsing(&mut self) -> Result<()> {
let output = if self.plan.uses_tmpfile() {
self.invocation
.tmpfile_contents
.as_ref()
.unwrap_or(&String::new())
.to_owned()
} else if self.plan.driver.output == OutputDestination::Stderr {
self.invocation.stderr.to_owned()
} else {
self.invocation.stdout.to_owned()
};
// If we have something to attempt to parse (which we don't if the tmpfile doesn't exist)
if !self.plan.uses_tmpfile() || self.invocation.tmpfile_contents.is_some() {
let output = if self.plan.uses_tmpfile() {
self.invocation.tmpfile_contents.as_ref().unwrap()
} else if self.plan.driver.output == OutputDestination::Stderr {
&self.invocation.stderr
} else {
&self.invocation.stdout
};

if output.is_empty() {
match self.plan.driver.output_missing {
OutputMissing::Error => {
self.invocation.exit_result =
qlty_types::analysis::v1::ExitResult::UnknownError.into();
self.log_error_output();
}
OutputMissing::NoIssues => {
self.invocation.exit_result =
qlty_types::analysis::v1::ExitResult::NoIssues.into();
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());
}
}
OutputMissing::Parse => self.parse_output(output),
}
} else {
self.parse_output(output);
}

Ok(())
}

fn parse_output(&mut self, output: String) {
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());
}
}
}

fn create_file_result_for_autofmts(&self) -> Result<Vec<FileResult>> {
let mut file_results: Vec<FileResult> = Vec::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ prepare_script = "mkdir ${linter} && echo dir %2 > ${linter}/ls.cmd || echo dir
script = "echo \"The plugin crashed for some reason\""
success_codes = [0]
output = "tmpfile"
missing_output_as_error = true

[[plugin]]
name = "exists"
Expand Down
4 changes: 2 additions & 2 deletions qlty-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub use language::Language;
pub use plugin::{
CheckTrigger, DriverBatchBy, DriverDef, DriverType, EnabledPlugin, ExtraPackage,
InvocationDirectoryDef, InvocationDirectoryType, IssueMode, OutputDestination, OutputFormat,
OutputMissing, PackageFileCandidate, Platform, PluginDef, PluginEnvironment, PluginFetch,
Runtime, SuggestionMode, TargetDef, TargetType,
PackageFileCandidate, Platform, PluginDef, PluginEnvironment, PluginFetch, Runtime,
SuggestionMode, TargetDef, TargetType,
};
pub use release::ReleaseDef;
pub use source::SourceDef;
Expand Down
23 changes: 3 additions & 20 deletions qlty-config/src/config/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ pub struct DriverDef {

#[serde(default)]
pub output_format: OutputFormat,

#[serde(default)]
pub output_missing: OutputMissing,

pub output_regex: Option<String>,

#[serde(default)]
Expand Down Expand Up @@ -115,6 +111,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 All @@ -125,22 +124,6 @@ fn default_max_batch() -> usize {
64
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, Default, JsonSchema)]
pub enum OutputMissing {
/// Raise an error if the output is missing
#[default]
#[serde(rename = "error")]
Error,

/// Interpret no output as no issues
#[serde(rename = "no_issues")]
NoIssues,

/// Hand the empty output to the parser for processing
#[serde(rename = "parse")]
Parse,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, Default, JsonSchema)]
pub enum DriverBatchBy {
#[default]
Expand Down
1 change: 1 addition & 0 deletions qlty-plugins/plugins/linters/eslint/plugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ batch = true
cache_results = true
max_batch = 40
known_good_version = "4.19.1"
missing_output_as_error = true
1 change: 1 addition & 0 deletions qlty-plugins/plugins/linters/kube-linter/plugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ output = "stdout"
output_format = "sarif"
output_category = "vulnerability"
output_level = "medium"
missing_output_as_error = true
target = { type = "literal", path = "." }
1 change: 0 additions & 1 deletion qlty-plugins/plugins/linters/radarlint/plugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ script = "java -jar ${linter}/radarlint.jar ${target}"
success_codes = [0]
output = "stdout"
output_format = "radarlint"
output_missing = "parse"
batch = true
cache_results = true
suggested = "targets"

0 comments on commit 13ebd82

Please sign in to comment.