Skip to content

Commit 1de2943

Browse files
authored
Merge pull request #16940 from RasmusWL/rasmuswl/BuiltinModuleExtractable
Python: Handle diagnostics writing for `BuiltinModuleExtractable`
2 parents 8a9f0bf + 354394d commit 1de2943

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

python/extractor/semmle/logging.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ def syntax_error_message(exception, unit):
373373
return error
374374

375375
def recursion_error_message(exception, unit):
376-
l = Location(file=unit.path)
376+
# if unit is a BuiltinModuleExtractable, there will be no path attribute
377+
l = Location(file=unit.path) if hasattr(unit, "path") else None
377378
return (DiagnosticMessage(Source("py/diagnostics/recursion-error", "Recursion error in Python extractor"), Severity.ERROR)
378379
.with_location(l)
379380
.text(exception.args[0])
@@ -383,7 +384,8 @@ def recursion_error_message(exception, unit):
383384
)
384385

385386
def internal_error_message(exception, unit):
386-
l = Location(file=unit.path)
387+
# if unit is a BuiltinModuleExtractable, there will be no path attribute
388+
l = Location(file=unit.path) if hasattr(unit, "path") else None
387389
return (DiagnosticMessage(Source("py/diagnostics/internal-error", "Internal error in Python extractor"), Severity.ERROR)
388390
.with_location(l)
389391
.text("Internal error")

python/extractor/semmle/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#Semantic version of extractor.
1212
#Update this if any changes are made
13-
VERSION = "6.1.1"
13+
VERSION = "6.1.2"
1414

1515
PY_EXTENSIONS = ".py", ".pyw"
1616

python/extractor/semmle/worker.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,24 @@ def _extract_loop(proc_id, queue, trap_dir, archive, options, reply_queue, logge
274274
# Syntax errors have already been handled in extractor.py
275275
reply_queue.put(("FAILURE", unit, None))
276276
except RecursionError as ex:
277-
error = recursion_error_message(ex, unit)
278-
diagnostics_writer.write(error)
279277
logger.error("Failed to extract %s: %s", unit, ex)
280278
logger.traceback(WARN)
279+
try:
280+
error = recursion_error_message(ex, unit)
281+
diagnostics_writer.write(error)
282+
except Exception as ex:
283+
logger.warning("Failed to write diagnostics: %s", ex)
284+
logger.traceback(WARN)
281285
reply_queue.put(("FAILURE", unit, None))
282286
except Exception as ex:
283-
error = internal_error_message(ex, unit)
284-
diagnostics_writer.write(error)
285287
logger.error("Failed to extract %s: %s", unit, ex)
286288
logger.traceback(WARN)
289+
try:
290+
error = internal_error_message(ex, unit)
291+
diagnostics_writer.write(error)
292+
except Exception as ex:
293+
logger.warning("Failed to write diagnostics: %s", ex)
294+
logger.traceback(WARN)
287295
reply_queue.put(("FAILURE", unit, None))
288296
else:
289297
reply_queue.put(("SUCCESS", unit, None))

0 commit comments

Comments
 (0)