From 09b24208afb3c5982690d5e568e56dfa881652c1 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 9 Oct 2023 16:26:40 -0700 Subject: [PATCH 1/6] Report all stacktraces in verbose mode Previously these were swallowed (unlike the ones in black/__init__.py) --- src/black/concurrency.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/black/concurrency.py b/src/black/concurrency.py index ce016578399..7dd0d8b96cf 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -12,6 +12,7 @@ from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor from multiprocessing import Manager from pathlib import Path +import traceback from typing import Any, Iterable, Optional, Set from mypy_extensions import mypyc_attr @@ -171,6 +172,8 @@ async def schedule_formatting( if task.cancelled(): cancelled.append(task) elif task.exception(): + if report.verbose: + traceback.print_exception(task.exception()) report.failed(src, str(task.exception())) else: changed = Changed.YES if task.result() else Changed.NO From 07691d5c3924b2a395eab9f47a21eb63869e2418 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 9 Oct 2023 16:28:18 -0700 Subject: [PATCH 2/6] changelog --- CHANGES.md | 2 ++ src/black/concurrency.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ffc63b3287d..fbe5fce21b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -42,6 +42,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 7dd0d8b96cf..88a67264482 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -9,10 +9,10 @@ import os import signal import sys +import traceback from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor from multiprocessing import Manager from pathlib import Path -import traceback from typing import Any, Iterable, Optional, Set from mypy_extensions import mypyc_attr From b7940eb1ba34b414939c03c5bb34d3dd05b89f2e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 9 Oct 2023 16:30:52 -0700 Subject: [PATCH 3/6] . --- src/black/concurrency.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/black/concurrency.py b/src/black/concurrency.py index 88a67264482..e3d6daf906c 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -173,7 +173,9 @@ async def schedule_formatting( cancelled.append(task) elif task.exception(): if report.verbose: - traceback.print_exception(task.exception()) + exc = task.exception() + assert exc is not None + traceback.print_exception(type(exc), exc, exc.__traceback__) report.failed(src, str(task.exception())) else: changed = Changed.YES if task.result() else Changed.NO From 454cdde052fbd9b6f30bf44b7cafa1ee06b3d3d2 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 9 Oct 2023 16:34:58 -0700 Subject: [PATCH 4/6] nit --- src/black/concurrency.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/black/concurrency.py b/src/black/concurrency.py index e3d6daf906c..28050f03530 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -172,11 +172,11 @@ async def schedule_formatting( if task.cancelled(): cancelled.append(task) elif task.exception(): + exc = task.exception() + assert exc is not None if report.verbose: - exc = task.exception() - assert exc is not None traceback.print_exception(type(exc), exc, exc.__traceback__) - report.failed(src, str(task.exception())) + 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 From 58e1b769059f9c12f60c031f4c299a962aa0dc81 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 9 Oct 2023 18:42:30 -0700 Subject: [PATCH 5/6] koo koo kachoo --- src/black/concurrency.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/black/concurrency.py b/src/black/concurrency.py index 28050f03530..1c9661125a2 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -171,9 +171,7 @@ async def schedule_formatting( src = tasks.pop(task) if task.cancelled(): cancelled.append(task) - elif task.exception(): - exc = task.exception() - assert exc is not None + elif (exc := task.exception()): if report.verbose: traceback.print_exception(type(exc), exc, exc.__traceback__) report.failed(src, str(exc)) From b5778a33229715ded18278a650b991be094f3696 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 9 Oct 2023 18:45:39 -0700 Subject: [PATCH 6/6] black --- src/black/concurrency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/black/concurrency.py b/src/black/concurrency.py index 1c9661125a2..55c96b66c86 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -171,7 +171,7 @@ async def schedule_formatting( src = tasks.pop(task) if task.cancelled(): cancelled.append(task) - elif (exc := task.exception()): + elif exc := task.exception(): if report.verbose: traceback.print_exception(type(exc), exc, exc.__traceback__) report.failed(src, str(exc))