From 0a956d473d5c215c3248df98dc0272005116c55b Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Sun, 7 Mar 2021 07:40:11 -0500 Subject: Print helpful error when toml decode fails (#4176) * Print helpful error when toml decode fails If loading a TOML config file fails, print the issue with the TOML file rather than dumping stack. Co-authored-by: Pierre Sassoulas --- CONTRIBUTORS.txt | 2 ++ pylint/config/find_default_config_files.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index cad49c23c..9932c5553 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -455,6 +455,8 @@ contributors: * Louis Sautier: contributor +* Quentin Young: contributor + * Alexander Kapshuna: contributor * Mark Byrne: contributor diff --git a/pylint/config/find_default_config_files.py b/pylint/config/find_default_config_files.py index 92d333f0f..126ac4a1e 100644 --- a/pylint/config/find_default_config_files.py +++ b/pylint/config/find_default_config_files.py @@ -5,11 +5,17 @@ import configparser import os import toml +from toml.decoder import TomlDecodeError def _toml_has_config(path): with open(path) as toml_handle: - content = toml.load(toml_handle) + try: + content = toml.load(toml_handle) + except TomlDecodeError as error: + print("Failed to load '{}': {}".format(path, str(error))) + return False + try: content["tool"]["pylint"] except KeyError: -- cgit v1.2.1