From 49e666685ee1e573cef8e99587e7d877356406fe Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 27 Mar 2022 14:32:27 +0200 Subject: [PATCH] Better error message when we cant write the crash files (#5987) * Display the error correctly if we can't write a crash report. Also catch any exceptions. --- pylint/config/__init__.py | 5 ++--- pylint/lint/utils.py | 11 +++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pylint/config/__init__.py b/pylint/config/__init__.py index 12f834d81b..16df5fd893 100644 --- a/pylint/config/__init__.py +++ b/pylint/config/__init__.py @@ -71,11 +71,10 @@ pathlib.Path(PYLINT_HOME).mkdir(parents=True, exist_ok=True) with open(spam_prevention_file, "w", encoding="utf8") as f: f.write("") - except Exception: # pylint: disable=broad-except - # Can't write in PYLINT_HOME ? + except Exception as exc: # pylint: disable=broad-except print( "Can't write the file that was supposed to " - f"prevent pylint.d deprecation spam in {PYLINT_HOME}." + f"prevent 'pylint.d' deprecation spam in {PYLINT_HOME} because of {exc}." ) diff --git a/pylint/lint/utils.py b/pylint/lint/utils.py index 8377dfdd44..7d402a0088 100644 --- a/pylint/lint/utils.py +++ b/pylint/lint/utils.py @@ -51,13 +51,16 @@ def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) -> pylint crashed with a ``{ex.__class__.__name__}`` and with the following stacktrace: ``` """ + template += traceback.format_exc() + template += "```\n" try: with open(issue_template_path, "a", encoding="utf8") as f: f.write(template) - traceback.print_exc(file=f) - f.write("```\n") - except FileNotFoundError: - print(f"Can't write the issue template for the crash in {issue_template_path}.") + except Exception as exc: # pylint: disable=broad-except + print( + f"Can't write the issue template for the crash in {issue_template_path} " + f"because of: '{exc}'\nHere's the content anyway:\n{template}." + ) return issue_template_path