Skip to content

Commit

Permalink
Better error message when we cant write the crash files (#5987)
Browse files Browse the repository at this point in the history
* Display the error correctly if we can't write a crash report. Also catch any exceptions.
  • Loading branch information
Pierre-Sassoulas committed Mar 27, 2022
1 parent 5c8384e commit 49e6666
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 2 additions & 3 deletions pylint/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
)


Expand Down
11 changes: 7 additions & 4 deletions pylint/lint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 49e6666

Please sign in to comment.