From 7aa37ea0adf864baf3ef3dfbcfaf5ff1ff780250 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:15:51 -0700 Subject: [PATCH] Report all stacktraces in verbose mode (#3938) Previously these were swallowed (unlike the ones in black/__init__.py) --- CHANGES.md | 2 ++ src/black/concurrency.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index fe4b621..6ad6308 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,6 +44,8 @@ - Black no longer attempts to provide special errors for attempting to format Python 2 code (#3933) +- Black will more consistently print stacktraces on internal errors in verbose mode + (#3938) ### _Blackd_ diff --git a/src/black/concurrency.py b/src/black/concurrency.py index ce01657..55c96b6 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -9,6 +9,7 @@ import logging import os import signal import sys +import traceback from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor from multiprocessing import Manager from pathlib import Path @@ -170,8 +171,10 @@ async def schedule_formatting( src = tasks.pop(task) if task.cancelled(): cancelled.append(task) - elif task.exception(): - report.failed(src, str(task.exception())) + elif exc := task.exception(): + if report.verbose: + traceback.print_exception(type(exc), exc, exc.__traceback__) + report.failed(src, str(exc)) else: changed = Changed.YES if task.result() else Changed.NO # If the file was written back or was successfully checked as -- 2.39.2