From 435cfc92cc8025b816d21430034a9b999fd631f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Rame=CC=81?= Date: Mon, 18 Mar 2024 15:12:41 +0100 Subject: [PATCH] chore: report to sentry the semgrep detailed errors --- src/semgrep/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/semgrep/index.ts b/src/semgrep/index.ts index d50c7ad..b631a72 100644 --- a/src/semgrep/index.ts +++ b/src/semgrep/index.ts @@ -1,3 +1,4 @@ +import * as Sentry from '@sentry/nextjs'; import { noCase } from 'change-case'; import { $ } from 'execa'; import fsSync from 'fs'; @@ -32,7 +33,17 @@ export async function analyzeWithSemgrep(folderPath: string, outputPath: string) try { await $`semgrep --metrics=off --config ${codeAnalysisRulesPath} ${folderPath} --json -o ${outputPath}`; } catch (error) { - console.log(`the details of the semgrep error can be read into ${outputPath}`); + console.log(`the details of the semgrep error can be read into ${outputPath}, but pushing it on Sentry too`); + + const codeAnalysisDataString = await fs.readFile(outputPath, 'utf-8'); + const codeAnalysisDataObject = JSON.parse(codeAnalysisDataString); + + // For easy analysis since from logs it's hard to see the whole object in case of concurrency calls + if (!!codeAnalysisDataObject.errors) { + Sentry.captureException(error, { + data: codeAnalysisDataObject.errors, + }); + } throw error; }