Skip to content

Commit 49e6666

Browse files
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.
1 parent 5c8384e commit 49e6666

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

pylint/config/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@
7171
pathlib.Path(PYLINT_HOME).mkdir(parents=True, exist_ok=True)
7272
with open(spam_prevention_file, "w", encoding="utf8") as f:
7373
f.write("")
74-
except Exception: # pylint: disable=broad-except
75-
# Can't write in PYLINT_HOME ?
74+
except Exception as exc: # pylint: disable=broad-except
7675
print(
7776
"Can't write the file that was supposed to "
78-
f"prevent pylint.d deprecation spam in {PYLINT_HOME}."
77+
f"prevent 'pylint.d' deprecation spam in {PYLINT_HOME} because of {exc}."
7978
)
8079

8180

pylint/lint/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) ->
5151
pylint crashed with a ``{ex.__class__.__name__}`` and with the following stacktrace:
5252
```
5353
"""
54+
template += traceback.format_exc()
55+
template += "```\n"
5456
try:
5557
with open(issue_template_path, "a", encoding="utf8") as f:
5658
f.write(template)
57-
traceback.print_exc(file=f)
58-
f.write("```\n")
59-
except FileNotFoundError:
60-
print(f"Can't write the issue template for the crash in {issue_template_path}.")
59+
except Exception as exc: # pylint: disable=broad-except
60+
print(
61+
f"Can't write the issue template for the crash in {issue_template_path} "
62+
f"because of: '{exc}'\nHere's the content anyway:\n{template}."
63+
)
6164
return issue_template_path
6265

6366

0 commit comments

Comments
 (0)