Skip to content

Commit 121f51c

Browse files
Prevent crash when parsing the toml to also crash pylint
Refer to #3181
1 parent 312c4f2 commit 121f51c

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

pylint/config/option_manager_mixin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ def read_config_file(self, config_file=None, verbose=None):
274274
self.set_current_module(config_file)
275275
parser = self.cfgfile_parser
276276
if config_file.endswith(".toml"):
277-
self._parse_toml(config_file, parser)
277+
try:
278+
self._parse_toml(config_file, parser)
279+
except toml.TomlDecodeError as e:
280+
self.add_message("config-parse-error", line=0, args=str(e))
278281
else:
279282
# Use this encoding in order to strip the BOM marker, if any.
280283
with open(config_file, encoding="utf_8_sig") as fp:

pylint/lint/pylinter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ def _load_reporter_by_class(reporter_class: str) -> type:
9898
"Used when an exception occurred while building the Astroid "
9999
"representation which could be handled by astroid.",
100100
),
101+
"F0011": (
102+
"error while parsing the configuration: %s",
103+
"config-parse-error",
104+
"Used when an exception occurred while parsing a pylint configuration file.",
105+
),
101106
"I0001": (
102107
"Unable to run raw checkers on built-in module %s",
103108
"raw-checker-failed",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
************* Module {abspath}
2+
{relpath}:1:0: F0010: error while code parsing: Found invalid character in key name: '*'. Try quoting the key name. (line 3 column 2 char 48) (parse-error)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TOML decode error crash pylint
2+
[tool.pylint]
3+
***
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
************* Module {abspath}
2+
{relpath}:1:0: E0014: Out-of-place setting encountered in top level configuration-section 'max-line-length' : '120' (bad-configuration-section)
3+
{relpath}:1:0: E0014: Out-of-place setting encountered in top level configuration-section 'disable' : '['C0330']' (bad-configuration-section)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This crashed previously see https://github.com/PyCQA/pylint/issues/3181
2+
[tool.pylint]
3+
max-line-length = 120
4+
disable = ["C0330"]

0 commit comments

Comments
 (0)