Path 1: 4 calls (1.0)

ValueError (1) AstroidError (1) Exception (1) AstroidBuildingError (1)

'/Users/andrehora/Documents/git/projects-pathspotter/pylint/tests/lint/test_pylinter.py' (2) '/private/var/folders/yp/qx0crmvd4sbck7chb52sws500000gn/T...

'/private/var/folders/yp/qx0crmvd4sbck7chb52sws500000gn/T/pytest-of-andrehora/pytest-178/test_crash_in_file0/pylint-crash-%Y' (1) '/private/var/folder...

PosixPath (4)

1def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) -> Path:
2    issue_template_path = (
3        Path(PYLINT_HOME) / datetime.now().strftime(str(crash_file_path))
4    ).resolve()
5    with open(filepath, encoding="utf8") as f:
6        file_content = f.read()
7    template = ""
8    if not issue_template_path.exists():
9        template = """\
10First, please verify that the bug is not already filled:
11https://github.com/PyCQA/pylint/issues/
12
13Then create a new crash issue:
14https://github.com/PyCQA/pylint/issues/new?assignees=&labels=crash%2Cneeds+triage&template=BUG-REPORT.yml
15
16"""
17    template += f"""\
18
19Issue title:
20Crash ``{ex}`` (if possible, be more specific about what made pylint crash)
21Content:
22When parsing the following file:
23
24<!--
25 If sharing the code is not an option, please state so,
26 but providing only the stacktrace would still be helpful.
27 -->
28
29```python
30{file_content}
31```
32
33pylint crashed with a ``{ex.__class__.__name__}`` and with the following stacktrace:
34```
35"""
36    template += traceback.format_exc()
37    template += "```\n"
38    try:
39        with open(issue_template_path, "a", encoding="utf8") as f:
40            f.write(template)
41    except Exception as exc:  # pylint: disable=broad-except
42        print(
43            f"Can't write the issue template for the crash in {issue_template_path} "
44            f"because of: '{exc}'\nHere's the content anyway:\n{template}.",
45            file=sys.stderr,
46        )
47    return issue_template_path