mirror of
https://github.com/github/codeql.git
synced 2025-12-18 09:43:15 +01:00
Merge pull request #16940 from RasmusWL/rasmuswl/BuiltinModuleExtractable
Python: Handle diagnostics writing for `BuiltinModuleExtractable`
This commit is contained in:
@@ -373,7 +373,8 @@ def syntax_error_message(exception, unit):
|
|||||||
return error
|
return error
|
||||||
|
|
||||||
def recursion_error_message(exception, unit):
|
def recursion_error_message(exception, unit):
|
||||||
l = Location(file=unit.path)
|
# if unit is a BuiltinModuleExtractable, there will be no path attribute
|
||||||
|
l = Location(file=unit.path) if hasattr(unit, "path") else None
|
||||||
return (DiagnosticMessage(Source("py/diagnostics/recursion-error", "Recursion error in Python extractor"), Severity.ERROR)
|
return (DiagnosticMessage(Source("py/diagnostics/recursion-error", "Recursion error in Python extractor"), Severity.ERROR)
|
||||||
.with_location(l)
|
.with_location(l)
|
||||||
.text(exception.args[0])
|
.text(exception.args[0])
|
||||||
@@ -383,7 +384,8 @@ def recursion_error_message(exception, unit):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def internal_error_message(exception, unit):
|
def internal_error_message(exception, unit):
|
||||||
l = Location(file=unit.path)
|
# if unit is a BuiltinModuleExtractable, there will be no path attribute
|
||||||
|
l = Location(file=unit.path) if hasattr(unit, "path") else None
|
||||||
return (DiagnosticMessage(Source("py/diagnostics/internal-error", "Internal error in Python extractor"), Severity.ERROR)
|
return (DiagnosticMessage(Source("py/diagnostics/internal-error", "Internal error in Python extractor"), Severity.ERROR)
|
||||||
.with_location(l)
|
.with_location(l)
|
||||||
.text("Internal error")
|
.text("Internal error")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from io import BytesIO
|
|||||||
|
|
||||||
#Semantic version of extractor.
|
#Semantic version of extractor.
|
||||||
#Update this if any changes are made
|
#Update this if any changes are made
|
||||||
VERSION = "6.1.1"
|
VERSION = "6.1.2"
|
||||||
|
|
||||||
PY_EXTENSIONS = ".py", ".pyw"
|
PY_EXTENSIONS = ".py", ".pyw"
|
||||||
|
|
||||||
|
|||||||
@@ -274,15 +274,23 @@ def _extract_loop(proc_id, queue, trap_dir, archive, options, reply_queue, logge
|
|||||||
# Syntax errors have already been handled in extractor.py
|
# Syntax errors have already been handled in extractor.py
|
||||||
reply_queue.put(("FAILURE", unit, None))
|
reply_queue.put(("FAILURE", unit, None))
|
||||||
except RecursionError as ex:
|
except RecursionError as ex:
|
||||||
|
logger.error("Failed to extract %s: %s", unit, ex)
|
||||||
|
logger.traceback(WARN)
|
||||||
|
try:
|
||||||
error = recursion_error_message(ex, unit)
|
error = recursion_error_message(ex, unit)
|
||||||
diagnostics_writer.write(error)
|
diagnostics_writer.write(error)
|
||||||
logger.error("Failed to extract %s: %s", unit, ex)
|
except Exception as ex:
|
||||||
|
logger.warning("Failed to write diagnostics: %s", ex)
|
||||||
logger.traceback(WARN)
|
logger.traceback(WARN)
|
||||||
reply_queue.put(("FAILURE", unit, None))
|
reply_queue.put(("FAILURE", unit, None))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
logger.error("Failed to extract %s: %s", unit, ex)
|
||||||
|
logger.traceback(WARN)
|
||||||
|
try:
|
||||||
error = internal_error_message(ex, unit)
|
error = internal_error_message(ex, unit)
|
||||||
diagnostics_writer.write(error)
|
diagnostics_writer.write(error)
|
||||||
logger.error("Failed to extract %s: %s", unit, ex)
|
except Exception as ex:
|
||||||
|
logger.warning("Failed to write diagnostics: %s", ex)
|
||||||
logger.traceback(WARN)
|
logger.traceback(WARN)
|
||||||
reply_queue.put(("FAILURE", unit, None))
|
reply_queue.put(("FAILURE", unit, None))
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user