mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Python: Add non-alert data for extractor diagnostics
This is basically just a port of the C++/JS queries added in: - https://github.com/github/codeql/pull/5414 (C++) - https://github.com/github/codeql/pull/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).
This commit is contained in:
23
python/ql/src/Diagnostics/ExtractionErrors.ql
Normal file
23
python/ql/src/Diagnostics/ExtractionErrors.ql
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @name Python extraction errors
|
||||
* @description List all extraction errors for Python files in the source code directory.
|
||||
* @kind diagnostic
|
||||
* @id py/diagnostics/extraction-errors
|
||||
*/
|
||||
|
||||
import python
|
||||
|
||||
/**
|
||||
* Gets the SARIF severity for errors.
|
||||
*
|
||||
* See point 3.27.10 in https://docs.oasis-open.org/sarif/sarif/v2.0/sarif-v2.0.html for
|
||||
* what error means.
|
||||
*/
|
||||
int getErrorSeverity() { result = 2 }
|
||||
|
||||
from SyntaxError error, File file
|
||||
where
|
||||
file = error.getFile() and
|
||||
exists(file.getRelativePath())
|
||||
select error, "Extraction failed in " + file + " with error " + error.getMessage(),
|
||||
getErrorSeverity()
|
||||
15
python/ql/src/Diagnostics/SuccessfullyExtractedFiles.ql
Normal file
15
python/ql/src/Diagnostics/SuccessfullyExtractedFiles.ql
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name Successfully extracted Python files
|
||||
* @description Lists all Python files in the source code directory that were extracted
|
||||
* without encountering an error.
|
||||
* @kind diagnostic
|
||||
* @id py/diagnostics/successfully-extracted-files
|
||||
*/
|
||||
|
||||
import python
|
||||
|
||||
from File file
|
||||
where
|
||||
not exists(SyntaxError e | e.getFile() = file) and
|
||||
exists(file.getRelativePath())
|
||||
select file, ""
|
||||
@@ -0,0 +1,2 @@
|
||||
| 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 |
|
||||
| syntax_error.py:1:31:1:31 | Syntax Error | Extraction failed in syntax_error.py with error Syntax Error | 2 |
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/ExtractionErrors.ql
|
||||
@@ -0,0 +1 @@
|
||||
| good_file.py:0:0:0:0 | good_file.py | |
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/SuccessfullyExtractedFiles.ql
|
||||
2
python/ql/test/query-tests/Diagnostics/bad_encoding.py
Normal file
2
python/ql/test/query-tests/Diagnostics/bad_encoding.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# Note: This file has been encoded in Windows 1252 to provoke encoding error
|
||||
print("wat<EFBFBD>")
|
||||
1
python/ql/test/query-tests/Diagnostics/good_file.py
Normal file
1
python/ql/test/query-tests/Diagnostics/good_file.py
Normal file
@@ -0,0 +1 @@
|
||||
print("hello world")
|
||||
1
python/ql/test/query-tests/Diagnostics/syntax_error.py
Normal file
1
python/ql/test/query-tests/Diagnostics/syntax_error.py
Normal file
@@ -0,0 +1 @@
|
||||
print("no closing parenthesis"
|
||||
Reference in New Issue
Block a user