Skip to content

Commit deb3db3

Browse files
committed
Python: Add non-alert data for extractor diagnostics
This is basically just a port of the C++/JS queries added in: - #5414 (C++) - #5656 (JS) SyntaxError should capture all errors we have information about. At least in `python/ql/src/semmlecode.python.dbscheme` the only match for `error` is `py_syntax_error_versioned` (which `SyntaxError` is based on).
1 parent 354dee1 commit deb3db3

File tree

9 files changed

+47
-0
lines changed

9 files changed

+47
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @name Python extraction errors
3+
* @description List all extraction errors for Python files in the source code directory.
4+
* @kind diagnostic
5+
* @id py/diagnostics/extraction-errors
6+
*/
7+
8+
import python
9+
10+
/**
11+
* Gets the SARIF severity for errors.
12+
*
13+
* See point 3.27.10 in https://docs.oasis-open.org/sarif/sarif/v2.0/sarif-v2.0.html for
14+
* what error means.
15+
*/
16+
int getErrorSeverity() { result = 2 }
17+
18+
from SyntaxError error, File file
19+
where
20+
file = error.getFile() and
21+
exists(file.getRelativePath())
22+
select error, "Extraction failed in " + file + " with error " + error.getMessage(),
23+
getErrorSeverity()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name Successfully extracted Python files
3+
* @description Lists all Python files in the source code directory that were extracted
4+
* without encountering an error.
5+
* @kind diagnostic
6+
* @id py/diagnostics/successfully-extracted-files
7+
*/
8+
9+
import python
10+
11+
from File file
12+
where
13+
not exists(SyntaxError e | e.getFile() = file) and
14+
exists(file.getRelativePath())
15+
select file, ""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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 88: 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 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Diagnostics/ExtractionErrors.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| good_file.py:0:0:0:0 | good_file.py | |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Diagnostics/SuccessfullyExtractedFiles.ql
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Note: This file has been encoded in Windows 1252 to provoke encoding error
2+
print("wat")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello world")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("no closing parenthesis"

0 commit comments

Comments
 (0)