From f225ba30ecfcb59877b46964e5d01f6cab8bd81f Mon Sep 17 00:00:00 2001 From: Yasmin Zhamborova Date: Mon, 14 Apr 2025 12:46:13 +0200 Subject: [PATCH 1/6] [PLUTO-1396] Handle tool errors gracefully --- cmd/analyze.go | 64 +++++++++++++-------- tools/eslintRunner.go | 19 ++++--- utils/sarif.go | 125 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 173 insertions(+), 35 deletions(-) diff --git a/cmd/analyze.go b/cmd/analyze.go index 56dbe9f2..d85456db 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -188,42 +188,33 @@ func getToolName(toolName string, version string) string { return toolName } -func runEslintAnalysis(workDirectory string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) { +func runEslintAnalysis(workDirectory string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) error { eslint := config.Config.Tools()["eslint"] eslintInstallationDirectory := eslint.InstallDir nodeRuntime := config.Config.Runtimes()["node"] nodeBinary := nodeRuntime.Binaries["node"] - tools.RunEslint(workDirectory, eslintInstallationDirectory, nodeBinary, pathsToCheck, autoFix, outputFile, outputFormat) + return tools.RunEslint(workDirectory, eslintInstallationDirectory, nodeBinary, pathsToCheck, autoFix, outputFile, outputFormat) } -func runTrivyAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) { +func runTrivyAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) error { trivy := config.Config.Tools()["trivy"] trivyBinary := trivy.Binaries["trivy"] - err := tools.RunTrivy(workDirectory, trivyBinary, pathsToCheck, outputFile, outputFormat) - if err != nil { - log.Fatalf("Error running Trivy: %v", err) - } + return tools.RunTrivy(workDirectory, trivyBinary, pathsToCheck, outputFile, outputFormat) } -func runPmdAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) { +func runPmdAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) error { pmd := config.Config.Tools()["pmd"] pmdBinary := pmd.Binaries["pmd"] - err := tools.RunPmd(workDirectory, pmdBinary, pathsToCheck, outputFile, outputFormat, config.Config) - if err != nil { - log.Fatalf("Error running PMD: %v", err) - } + return tools.RunPmd(workDirectory, pmdBinary, pathsToCheck, outputFile, outputFormat, config.Config) } -func runPylintAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) { +func runPylintAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) error { pylint := config.Config.Tools()["pylint"] - err := tools.RunPylint(workDirectory, pylint, pathsToCheck, outputFile, outputFormat) - if err != nil { - log.Fatalf("Error running Pylint: %v", err) - } + return tools.RunPylint(workDirectory, pylint, pathsToCheck, outputFile, outputFormat) } var analyzeCmd = &cobra.Command{ @@ -262,13 +253,22 @@ var analyzeCmd = &cobra.Command{ defer os.RemoveAll(tmpDir) var sarifOutputs []string + failedTools := make(map[string]error) for toolName := range toolsToRun { log.Printf("Running %s...\n", toolName) tmpFile := filepath.Join(tmpDir, fmt.Sprintf("%s.sarif", toolName)) - runTool(workDirectory, toolName, args, tmpFile) + if err := runTool(workDirectory, toolName, args, tmpFile); err != nil { + log.Printf("Warning: Tool %s failed: %v\n", toolName, err) + failedTools[toolName] = err + continue + } sarifOutputs = append(sarifOutputs, tmpFile) } + if len(sarifOutputs) == 0 && len(failedTools) > 0 { + log.Fatal("All tools failed to run. No analysis results available.") + } + // create output file tmp file tmpOutputFile := filepath.Join(tmpDir, "merged.sarif") @@ -277,6 +277,22 @@ var analyzeCmd = &cobra.Command{ log.Fatalf("Failed to merge SARIF outputs: %v", err) } + // Add error runs to the merged SARIF + if len(failedTools) > 0 { + mergedSarif, err := utils.ReadSarifFile(tmpOutputFile) + if err != nil { + log.Fatalf("Failed to read merged SARIF: %v", err) + } + + for toolName, err := range failedTools { + utils.AddErrorRun(&mergedSarif, toolName, err.Error()) + } + + if err := utils.WriteSarifFile(mergedSarif, tmpOutputFile); err != nil { + log.Fatalf("Failed to write updated SARIF: %v", err) + } + } + if outputFile != "" { // copy tmpOutputFile to outputFile content, err := os.ReadFile(tmpOutputFile) @@ -302,17 +318,17 @@ var analyzeCmd = &cobra.Command{ }, } -func runTool(workDirectory string, toolName string, args []string, outputFile string) { +func runTool(workDirectory string, toolName string, args []string, outputFile string) error { switch toolName { case "eslint": - runEslintAnalysis(workDirectory, args, autoFix, outputFile, outputFormat) + return runEslintAnalysis(workDirectory, args, autoFix, outputFile, outputFormat) case "trivy": - runTrivyAnalysis(workDirectory, args, outputFile, outputFormat) + return runTrivyAnalysis(workDirectory, args, outputFile, outputFormat) case "pmd": - runPmdAnalysis(workDirectory, args, outputFile, outputFormat) + return runPmdAnalysis(workDirectory, args, outputFile, outputFormat) case "pylint": - runPylintAnalysis(workDirectory, args, outputFile, outputFormat) + return runPylintAnalysis(workDirectory, args, outputFile, outputFormat) default: - log.Printf("Warning: Unsupported tool: %s\n", toolName) + return fmt.Errorf("unsupported tool: %s", toolName) } } diff --git a/tools/eslintRunner.go b/tools/eslintRunner.go index 9e8314e0..1ff5ad1d 100644 --- a/tools/eslintRunner.go +++ b/tools/eslintRunner.go @@ -2,6 +2,7 @@ package tools import ( "codacy/cli-v2/config" + "fmt" "os" "os/exec" "path/filepath" @@ -10,7 +11,7 @@ import ( // * Run from the root of the repo we want to analyse // * NODE_PATH="/node_modules" // * The local installed ESLint should have the @microsoft/eslint-formatter-sarif installed -func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory string, nodeBinary string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) { +func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory string, nodeBinary string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) error { eslintInstallationNodeModules := filepath.Join(eslintInstallationDirectory, "node_modules") eslintJsPath := filepath.Join(eslintInstallationNodeModules, ".bin", "eslint") @@ -50,10 +51,14 @@ func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory nodePathEnv := "NODE_PATH=" + eslintInstallationNodeModules cmd.Env = append(cmd.Env, nodePathEnv) - // DEBUG - // fmt.Println(cmd.Env) - // fmt.Println(cmd) - - // TODO eslint returns 1 when it finds errors, so we're not propagating it - cmd.Run() + // Run the command and handle errors + err := cmd.Run() + if err != nil { + // ESLint returns 1 when it finds errors, which is not a failure + if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 1 { + return nil + } + return fmt.Errorf("failed to run ESLint: %w", err) + } + return nil } diff --git a/utils/sarif.go b/utils/sarif.go index d0c3c850..36e416c8 100644 --- a/utils/sarif.go +++ b/utils/sarif.go @@ -27,8 +27,9 @@ type SarifReport struct { } type Run struct { - Tool Tool `json:"tool"` - Results []Result `json:"results"` + Tool Tool `json:"tool"` + Results []Result `json:"results"` + Invocations []Invocation `json:"invocations,omitempty"` } type Tool struct { @@ -80,18 +81,89 @@ type ArtifactLocation struct { type Region struct { StartLine int `json:"startLine"` StartColumn int `json:"startColumn"` + EndLine int `json:"endLine"` + EndColumn int `json:"endColumn"` +} + +type Invocation struct { + ExecutionSuccessful bool `json:"executionSuccessful"` + ExitCode int `json:"exitCode"` + ExitSignalName string `json:"exitSignalName"` + ExitSignalNumber int `json:"exitSignalNumber"` + Stderr Artifact `json:"stderr"` +} + +type Artifact struct { + Text string `json:"text"` } type MessageText struct { Text string `json:"text"` } +// ReadSarifFile reads a SARIF file and returns its contents +func ReadSarifFile(file string) (SarifReport, error) { + data, err := os.ReadFile(file) + if err != nil { + return SarifReport{}, fmt.Errorf("failed to read SARIF file: %w", err) + } + + var sarif SarifReport + if err := json.Unmarshal(data, &sarif); err != nil { + return SarifReport{}, fmt.Errorf("failed to parse SARIF file: %w", err) + } + + return sarif, nil +} + +// WriteSarifFile writes a SARIF report to a file +func WriteSarifFile(sarif SarifReport, outputFile string) error { + out, err := os.Create(outputFile) + if err != nil { + return fmt.Errorf("failed to create output file: %w", err) + } + defer out.Close() + + encoder := json.NewEncoder(out) + encoder.SetIndent("", " ") + if err := encoder.Encode(sarif); err != nil { + return fmt.Errorf("failed to write SARIF: %w", err) + } + + return nil +} + +// AddErrorRun adds an error run to an existing SARIF report +func AddErrorRun(sarif *SarifReport, toolName string, errorMessage string) { + errorRun := Run{ + Tool: Tool{ + Driver: Driver{ + Name: toolName, + Version: "1.0.0", + }, + }, + Invocations: []Invocation{ + { + ExecutionSuccessful: false, + ExitCode: 1, + ExitSignalName: "error", + ExitSignalNumber: 1, + Stderr: Artifact{ + Text: errorMessage, + }, + }, + }, + Results: []Result{}, + } + sarif.Runs = append(sarif.Runs, errorRun) +} + // ConvertPylintToSarif converts Pylint JSON output to SARIF format func ConvertPylintToSarif(pylintOutput []byte) []byte { var issues []PylintIssue if err := json.Unmarshal(pylintOutput, &issues); err != nil { - // If parsing fails, return empty SARIF report - return createEmptySarifReport() + // If parsing fails, return empty SARIF report with error + return createEmptySarifReportWithError(err.Error()) } // Create SARIF report @@ -108,6 +180,17 @@ func ConvertPylintToSarif(pylintOutput []byte) []byte { }, }, Results: make([]Result, 0, len(issues)), + Invocations: []Invocation{ + { + ExecutionSuccessful: true, // Pylint ran successfully if we got here + ExitCode: 0, + ExitSignalName: "", + ExitSignalNumber: 0, + Stderr: Artifact{ + Text: "", + }, + }, + }, }, }, } @@ -161,6 +244,29 @@ func getSarifLevel(pylintType string) string { // createEmptySarifReport creates an empty SARIF report in case of errors func createEmptySarifReport() []byte { + emptyReport := SarifReport{ + Version: "2.1.0", + Schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", + Runs: []Run{ + { + Tool: Tool{ + Driver: Driver{ + Name: "Pylint", + Version: "3.3.6", + InformationURI: "https://pylint.org", + }, + }, + Results: []Result{}, + Invocations: []Invocation{}, + }, + }, + } + sarifData, _ := json.MarshalIndent(emptyReport, "", " ") + return sarifData +} + +// createEmptySarifReportWithError creates an empty SARIF report with error information +func createEmptySarifReportWithError(errorMessage string) []byte { emptyReport := SarifReport{ Version: "2.1.0", Schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", @@ -174,6 +280,17 @@ func createEmptySarifReport() []byte { }, }, Results: []Result{}, + Invocations: []Invocation{ + { + ExecutionSuccessful: false, + ExitCode: 1, + ExitSignalName: "error", + ExitSignalNumber: 1, + Stderr: Artifact{ + Text: errorMessage, + }, + }, + }, }, }, } From f9d4372a81f4edcf6b0b5799acedc5f6b63fc6fc Mon Sep 17 00:00:00 2001 From: Yasmin Zhamborova Date: Mon, 14 Apr 2025 13:46:54 +0200 Subject: [PATCH 2/6] [PLUTO-1396] Handle sarif err --- utils/sarif.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/utils/sarif.go b/utils/sarif.go index 36e416c8..120eb31a 100644 --- a/utils/sarif.go +++ b/utils/sarif.go @@ -261,7 +261,11 @@ func createEmptySarifReport() []byte { }, }, } - sarifData, _ := json.MarshalIndent(emptyReport, "", " ") + sarifData, err := json.MarshalIndent(emptyReport, "", " ") + if err != nil { + fmt.Fprintf(os.Stderr, "Error marshaling empty SARIF report: %v\n", err) + return []byte("{}") + } return sarifData } @@ -294,7 +298,11 @@ func createEmptySarifReportWithError(errorMessage string) []byte { }, }, } - sarifData, _ := json.MarshalIndent(emptyReport, "", " ") + sarifData, err := json.MarshalIndent(emptyReport, "", " ") + if err != nil { + fmt.Fprintf(os.Stderr, "Error marshaling SARIF report with error: %v\n", err) + return []byte("{}") + } return sarifData } From 235225c0f2ccb76483a0148ff0fc7fdc833f8a20 Mon Sep 17 00:00:00 2001 From: Yasmin Zhamborova Date: Tue, 15 Apr 2025 12:08:59 +0200 Subject: [PATCH 3/6] [PLUTO-1396] Do not gather fatal failures in sarif --- cmd/analyze.go | 29 ++------- tools/eslintRunner.go | 4 ++ utils/sarif.go | 135 ++---------------------------------------- 3 files changed, 14 insertions(+), 154 deletions(-) diff --git a/cmd/analyze.go b/cmd/analyze.go index d85456db..6886b3cb 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -253,22 +253,16 @@ var analyzeCmd = &cobra.Command{ defer os.RemoveAll(tmpDir) var sarifOutputs []string - failedTools := make(map[string]error) for toolName := range toolsToRun { log.Printf("Running %s...\n", toolName) tmpFile := filepath.Join(tmpDir, fmt.Sprintf("%s.sarif", toolName)) if err := runTool(workDirectory, toolName, args, tmpFile); err != nil { - log.Printf("Warning: Tool %s failed: %v\n", toolName, err) - failedTools[toolName] = err + log.Printf("Tool failed to run: %s: %v\n", toolName, err) continue } sarifOutputs = append(sarifOutputs, tmpFile) } - if len(sarifOutputs) == 0 && len(failedTools) > 0 { - log.Fatal("All tools failed to run. No analysis results available.") - } - // create output file tmp file tmpOutputFile := filepath.Join(tmpDir, "merged.sarif") @@ -277,22 +271,6 @@ var analyzeCmd = &cobra.Command{ log.Fatalf("Failed to merge SARIF outputs: %v", err) } - // Add error runs to the merged SARIF - if len(failedTools) > 0 { - mergedSarif, err := utils.ReadSarifFile(tmpOutputFile) - if err != nil { - log.Fatalf("Failed to read merged SARIF: %v", err) - } - - for toolName, err := range failedTools { - utils.AddErrorRun(&mergedSarif, toolName, err.Error()) - } - - if err := utils.WriteSarifFile(mergedSarif, tmpOutputFile); err != nil { - log.Fatalf("Failed to write updated SARIF: %v", err) - } - } - if outputFile != "" { // copy tmpOutputFile to outputFile content, err := os.ReadFile(tmpOutputFile) @@ -312,7 +290,10 @@ var analyzeCmd = &cobra.Command{ // Run tools without merging outputs for toolName := range toolsToRun { log.Printf("Running %s...\n", toolName) - runTool(workDirectory, toolName, args, outputFile) + if err := runTool(workDirectory, toolName, args, outputFile); err != nil { + log.Printf("Tool failed to run: %s: %v\n", toolName, err) + continue + } } } }, diff --git a/tools/eslintRunner.go b/tools/eslintRunner.go index 1ff5ad1d..f7212d6d 100644 --- a/tools/eslintRunner.go +++ b/tools/eslintRunner.go @@ -51,6 +51,10 @@ func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory nodePathEnv := "NODE_PATH=" + eslintInstallationNodeModules cmd.Env = append(cmd.Env, nodePathEnv) + // DEBUG + // fmt.Println(cmd.Env) + // fmt.Println(cmd) + // Run the command and handle errors err := cmd.Run() if err != nil { diff --git a/utils/sarif.go b/utils/sarif.go index 120eb31a..d0c3c850 100644 --- a/utils/sarif.go +++ b/utils/sarif.go @@ -27,9 +27,8 @@ type SarifReport struct { } type Run struct { - Tool Tool `json:"tool"` - Results []Result `json:"results"` - Invocations []Invocation `json:"invocations,omitempty"` + Tool Tool `json:"tool"` + Results []Result `json:"results"` } type Tool struct { @@ -81,89 +80,18 @@ type ArtifactLocation struct { type Region struct { StartLine int `json:"startLine"` StartColumn int `json:"startColumn"` - EndLine int `json:"endLine"` - EndColumn int `json:"endColumn"` -} - -type Invocation struct { - ExecutionSuccessful bool `json:"executionSuccessful"` - ExitCode int `json:"exitCode"` - ExitSignalName string `json:"exitSignalName"` - ExitSignalNumber int `json:"exitSignalNumber"` - Stderr Artifact `json:"stderr"` -} - -type Artifact struct { - Text string `json:"text"` } type MessageText struct { Text string `json:"text"` } -// ReadSarifFile reads a SARIF file and returns its contents -func ReadSarifFile(file string) (SarifReport, error) { - data, err := os.ReadFile(file) - if err != nil { - return SarifReport{}, fmt.Errorf("failed to read SARIF file: %w", err) - } - - var sarif SarifReport - if err := json.Unmarshal(data, &sarif); err != nil { - return SarifReport{}, fmt.Errorf("failed to parse SARIF file: %w", err) - } - - return sarif, nil -} - -// WriteSarifFile writes a SARIF report to a file -func WriteSarifFile(sarif SarifReport, outputFile string) error { - out, err := os.Create(outputFile) - if err != nil { - return fmt.Errorf("failed to create output file: %w", err) - } - defer out.Close() - - encoder := json.NewEncoder(out) - encoder.SetIndent("", " ") - if err := encoder.Encode(sarif); err != nil { - return fmt.Errorf("failed to write SARIF: %w", err) - } - - return nil -} - -// AddErrorRun adds an error run to an existing SARIF report -func AddErrorRun(sarif *SarifReport, toolName string, errorMessage string) { - errorRun := Run{ - Tool: Tool{ - Driver: Driver{ - Name: toolName, - Version: "1.0.0", - }, - }, - Invocations: []Invocation{ - { - ExecutionSuccessful: false, - ExitCode: 1, - ExitSignalName: "error", - ExitSignalNumber: 1, - Stderr: Artifact{ - Text: errorMessage, - }, - }, - }, - Results: []Result{}, - } - sarif.Runs = append(sarif.Runs, errorRun) -} - // ConvertPylintToSarif converts Pylint JSON output to SARIF format func ConvertPylintToSarif(pylintOutput []byte) []byte { var issues []PylintIssue if err := json.Unmarshal(pylintOutput, &issues); err != nil { - // If parsing fails, return empty SARIF report with error - return createEmptySarifReportWithError(err.Error()) + // If parsing fails, return empty SARIF report + return createEmptySarifReport() } // Create SARIF report @@ -180,17 +108,6 @@ func ConvertPylintToSarif(pylintOutput []byte) []byte { }, }, Results: make([]Result, 0, len(issues)), - Invocations: []Invocation{ - { - ExecutionSuccessful: true, // Pylint ran successfully if we got here - ExitCode: 0, - ExitSignalName: "", - ExitSignalNumber: 0, - Stderr: Artifact{ - Text: "", - }, - }, - }, }, }, } @@ -244,33 +161,6 @@ func getSarifLevel(pylintType string) string { // createEmptySarifReport creates an empty SARIF report in case of errors func createEmptySarifReport() []byte { - emptyReport := SarifReport{ - Version: "2.1.0", - Schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", - Runs: []Run{ - { - Tool: Tool{ - Driver: Driver{ - Name: "Pylint", - Version: "3.3.6", - InformationURI: "https://pylint.org", - }, - }, - Results: []Result{}, - Invocations: []Invocation{}, - }, - }, - } - sarifData, err := json.MarshalIndent(emptyReport, "", " ") - if err != nil { - fmt.Fprintf(os.Stderr, "Error marshaling empty SARIF report: %v\n", err) - return []byte("{}") - } - return sarifData -} - -// createEmptySarifReportWithError creates an empty SARIF report with error information -func createEmptySarifReportWithError(errorMessage string) []byte { emptyReport := SarifReport{ Version: "2.1.0", Schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", @@ -284,25 +174,10 @@ func createEmptySarifReportWithError(errorMessage string) []byte { }, }, Results: []Result{}, - Invocations: []Invocation{ - { - ExecutionSuccessful: false, - ExitCode: 1, - ExitSignalName: "error", - ExitSignalNumber: 1, - Stderr: Artifact{ - Text: errorMessage, - }, - }, - }, }, }, } - sarifData, err := json.MarshalIndent(emptyReport, "", " ") - if err != nil { - fmt.Fprintf(os.Stderr, "Error marshaling SARIF report with error: %v\n", err) - return []byte("{}") - } + sarifData, _ := json.MarshalIndent(emptyReport, "", " ") return sarifData } From 2bc5e47e8f21461983487021c586f7bb08a86a64 Mon Sep 17 00:00:00 2001 From: Yasmin Zhamborova Date: Tue, 15 Apr 2025 12:31:51 +0200 Subject: [PATCH 4/6] [PLUTO-1396] consistent error log --- tools/pmdRunner.go | 3 ++- tools/pylintRunner.go | 2 +- tools/trivyRunner.go | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/pmdRunner.go b/tools/pmdRunner.go index 901d09d5..c59a2b0c 100644 --- a/tools/pmdRunner.go +++ b/tools/pmdRunner.go @@ -2,6 +2,7 @@ package tools import ( "codacy/cli-v2/config" + "fmt" "os" "os/exec" "strings" @@ -56,7 +57,7 @@ func RunPmd(repositoryToAnalyseDirectory string, pmdBinary string, pathsToCheck // Exit code 4 means violations found – treat as success return nil } - return err + return fmt.Errorf("failed to run PMD: %w", err) } return nil } diff --git a/tools/pylintRunner.go b/tools/pylintRunner.go index 5d907837..84cfecdf 100644 --- a/tools/pylintRunner.go +++ b/tools/pylintRunner.go @@ -59,7 +59,7 @@ func RunPylint(workDirectory string, toolInfo *plugins.ToolInfo, files []string, // Pylint returns non-zero exit code when it finds issues // We should not treat this as an error if _, ok := err.(*exec.ExitError); !ok { - return fmt.Errorf("failed to run pylint: %w", err) + return fmt.Errorf("failed to run Pylint: %w", err) } } diff --git a/tools/trivyRunner.go b/tools/trivyRunner.go index 8e8e3522..8f580553 100644 --- a/tools/trivyRunner.go +++ b/tools/trivyRunner.go @@ -2,6 +2,7 @@ package tools import ( "codacy/cli-v2/config" + "fmt" "os" "os/exec" ) @@ -35,5 +36,9 @@ func RunTrivy(repositoryToAnalyseDirectory string, trivyBinary string, pathsToCh cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout - return cmd.Run() + err := cmd.Run() + if err != nil { + return fmt.Errorf("failed to run Trivy: %w", err) + } + return nil } From 011554fee560753cbaaba935be7d290c99be7053 Mon Sep 17 00:00:00 2001 From: Yasmin Zhamborova Date: Tue, 15 Apr 2025 12:50:25 +0200 Subject: [PATCH 5/6] [PLUTO-1396] rem continue --- cmd/analyze.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/analyze.go b/cmd/analyze.go index 6886b3cb..147d6dd7 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -258,7 +258,6 @@ var analyzeCmd = &cobra.Command{ tmpFile := filepath.Join(tmpDir, fmt.Sprintf("%s.sarif", toolName)) if err := runTool(workDirectory, toolName, args, tmpFile); err != nil { log.Printf("Tool failed to run: %s: %v\n", toolName, err) - continue } sarifOutputs = append(sarifOutputs, tmpFile) } From 484c72c901ee42fdb21c5d17b4356ab13f73a8d2 Mon Sep 17 00:00:00 2001 From: Yasmin Zhamborova Date: Tue, 15 Apr 2025 12:53:27 +0200 Subject: [PATCH 6/6] [PLUTO-1396] rem continue --- cmd/analyze.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/analyze.go b/cmd/analyze.go index 147d6dd7..72d3bd93 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -291,7 +291,6 @@ var analyzeCmd = &cobra.Command{ log.Printf("Running %s...\n", toolName) if err := runTool(workDirectory, toolName, args, outputFile); err != nil { log.Printf("Tool failed to run: %s: %v\n", toolName, err) - continue } } }