Skip to content

Commit

Permalink
chore: report to sentry the semgrep detailed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sneko committed Mar 18, 2024
1 parent b444735 commit 435cfc9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/semgrep/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs';
import { noCase } from 'change-case';
import { $ } from 'execa';
import fsSync from 'fs';
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 435cfc9

Please sign in to comment.