Skip to content

Commit 562a57b

Browse files
authored
Merge pull request github#6928 from RasmusWL/diagnostic-as-warning
Python: Improve SARIF severity level reporting of extractor diagnostics
2 parents 1fe772a + 852e987 commit 562a57b

File tree

6 files changed

+41
-26
lines changed

6 files changed

+41
-26
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
codescanning
2+
* Problems with extraction that in most cases won't completely break the analysis are now reported as warnings rather than errors.

python/ql/src/Diagnostics/ExtractionErrors.ql

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @name Python extraction warnings
3+
* @description List all extraction warnings for Python files in the source code directory.
4+
* @kind diagnostic
5+
* @id py/diagnostics/extraction-warnings
6+
*/
7+
8+
import python
9+
10+
/**
11+
* Gets the SARIF severity for warnings.
12+
*
13+
* See https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10541338
14+
*/
15+
int getWarningSeverity() { result = 1 }
16+
17+
// The spec
18+
// https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10541338
19+
// defines error and warning as:
20+
//
21+
// "error": A serious problem was found. The condition encountered by the tool resulted
22+
// in the analysis being halted or caused the results to be incorrect or incomplete.
23+
//
24+
// "warning": A problem that is not considered serious was found. The condition
25+
// encountered by the tool is such that it is uncertain whether a problem occurred, or
26+
// is such that the analysis might be incomplete but the results that were generated are
27+
// probably valid.
28+
//
29+
// So SyntaxErrors are reported at the warning level, since analysis might be incomplete
30+
// but the results that were generated are probably valid.
31+
from SyntaxError error, File file
32+
where
33+
file = error.getFile() and
34+
exists(file.getRelativePath())
35+
select error, "Extraction failed in " + file + " with error " + error.getMessage(),
36+
getWarningSeverity()

python/ql/test/query-tests/Diagnostics/ExtractionErrors.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| bad_encoding.py:2:11:2:11 | Encoding Error | Extraction failed in bad_encoding.py with error 'utf-8' codec can't decode byte 0x9d in position 87: invalid start byte | 2 |
2-
| syntax_error.py:1:31:1:31 | Syntax Error | Extraction failed in syntax_error.py with error Syntax Error | 2 |
1+
| bad_encoding.py:2:11:2:11 | Encoding Error | Extraction failed in bad_encoding.py with error 'utf-8' codec can't decode byte 0x9d in position 87: invalid start byte | 1 |
2+
| syntax_error.py:1:31:1:31 | Syntax Error | Extraction failed in syntax_error.py with error Syntax Error | 1 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Diagnostics/ExtractionWarnings.ql

0 commit comments

Comments
 (0)