fix(config): added error message print when config loading fails

closes #531
This commit is contained in:
Christopher Pickering 2023-02-07 08:53:38 -06:00
parent b47c6bba85
commit e21fa29dc2
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
17 changed files with 8 additions and 40 deletions

View file

@ -248,9 +248,7 @@ def main(
ascii=progress_char,
leave=False,
) as pbar:
for future in as_completed(futures):
file_errors.append(future.result())
pbar.update()
elapsed = pbar.format_interval(pbar.format_dict["elapsed"])

View file

@ -32,7 +32,6 @@ def format_template_tags(config: Config, attributes: str, spacing: int) -> str:
indent_adder = spacing or 0
for line_number, line in enumerate(attributes.splitlines()):
# when checking for template tag, use "match" to force start of line check.
if re.match(
re.compile(config.template_unindent, re.I | re.X), line.strip()

View file

@ -136,7 +136,6 @@ def condense_html(html: str, config: Config) -> str:
# should we add blank lines before load tags?
if config.blank_line_before_tag:
for tag in [x.strip() for x in config.blank_line_before_tag.split(",")]:
html = re.sub(
re.compile(
rf"(?<!^\n)((?:{{%\s*?{tag}\b[^}}]+?%}}\n?)+)",

View file

@ -26,7 +26,6 @@ def format_css(html: str, config: Config) -> str:
# add indent back
ignore_indent = False
for line in beautified_lines:
if re.search(
re.compile(
r"\/\*[ ]*?beautify[ ]+?ignore:end[ ]*?\*\/",
@ -38,7 +37,6 @@ def format_css(html: str, config: Config) -> str:
ignore_indent = False
if ignore_indent is False and line:
beautified += "\n" + inner_indent + line
else:
beautified += "\n" + line

View file

@ -37,7 +37,6 @@ def indent_html(rawcode: str, config: Config) -> str:
ignored_level = 0
for item in rawcode_flat_list:
# if a raw tag first line
if not is_block_raw and is_ignored_block_opening(config, item):
is_raw_first_line = True
@ -225,7 +224,6 @@ def indent_html(rawcode: str, config: Config) -> str:
def fix_non_handlebars_template_tags(
html: str, out_format: str, match: re.Match
) -> str:
if inside_ignored_block(config, html, match):
return match.group()
@ -255,7 +253,6 @@ def indent_html(rawcode: str, config: Config) -> str:
def fix_handlebars_template_tags(
html: str, out_format: str, match: re.Match
) -> str:
if inside_ignored_block(config, html, match):
return match.group()

View file

@ -27,7 +27,6 @@ def format_js(html: str, config: Config) -> str:
# add indent back
ignore_indent = False
for line in beautified_lines:
if re.search(
re.compile(
r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):end[ ]*?\*\/",

View file

@ -71,7 +71,6 @@ def lint_file(config: Config, this_file: Path) -> Dict:
# rule H025 is a special case where the output must be an even number.
if rule["name"] == "H025":
open_tags: List[re.Match] = []
# for match in re.finditer(

View file

@ -114,7 +114,6 @@ def build_output(error: dict, config: Config) -> int:
)
for message_dict in errors:
line = Fore.BLUE + message_dict["line"] + Style.RESET_ALL
code = (
(Fore.RED if message_dict["code"][:1] == "E" else Fore.YELLOW)
@ -205,14 +204,12 @@ def build_stats_output(errors: List[Optional[Any]], config: Config) -> int:
)
if messages and codes:
longest_code = len(max(messages.keys(), key=len))
longest_count = len(
str(max(Counter(codes).values(), key=lambda x: len(str(x))))
)
for code in sorted(Counter(codes).items()):
code_space = (longest_code - len(str(code[0]))) * " "
count_space = (longest_count - len(str(code[1]))) * " "

View file

@ -29,7 +29,6 @@ logger = logging.getLogger(__name__)
def find_project_root(src: Path) -> Path:
"""Attempt to get the project root."""
for directory in [src, *src.resolve().parents]:
if (directory / ".git").exists():
return directory
@ -108,9 +107,12 @@ def load_project_settings(src: Path, config: Optional[str]) -> Dict:
)
# pylint: disable=broad-except
except BaseException:
logger.info(
"Failed to load config file. Ensure file exists and is in json format."
except BaseException as error:
logger.error(
"%sFailed to load config file %s. %s",
Fore.RED,
Path(config).resolve(),
error,
)
pyproject_file = find_pyproject(src)
@ -131,8 +133,8 @@ def load_project_settings(src: Path, config: Optional[str]) -> Dict:
**json.loads(djlintrc_file.read_text(encoding="utf8")),
}
# pylint: disable=broad-except
except BaseException:
logger.info("Failed to load .djlintrc file.")
except BaseException as error:
logger.error("%sFailed to load .djlintrc file. %s", Fore.RED, error)
return djlint_content
@ -214,7 +216,6 @@ class Config:
configuration: Optional[str] = None,
statistics: bool = False,
):
self.reformat = reformat
self.check = check
self.lint = lint

View file

@ -31,7 +31,6 @@ def test_with_config(runner: CliRunner) -> None:
def test_without_config(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,

View file

@ -15,7 +15,6 @@ from src.djlint import main as djlint
def test_config(runner: CliRunner) -> None:
result = runner.invoke(
djlint,
[

View file

@ -15,7 +15,6 @@ from src.djlint import main as djlint
def test_config(runner: CliRunner) -> None:
result = runner.invoke(
djlint,
[

View file

@ -27,7 +27,6 @@ from tests.conftest import reformat
def test_aurelia(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,

View file

@ -104,7 +104,6 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
@ -314,7 +313,6 @@ def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
@ -338,7 +336,6 @@ def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None:
def test_html_comments(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
@ -483,7 +480,6 @@ def test_html_comments(runner: CliRunner, tmp_file: TextIO) -> None:
def test_issue_9368_3(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
@ -495,7 +491,6 @@ def test_issue_9368_3(runner: CliRunner, tmp_file: TextIO) -> None:
def test_issue_9368(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
@ -533,7 +528,6 @@ def test_issue_9368(runner: CliRunner, tmp_file: TextIO) -> None:
def test_void_elements(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,

View file

@ -49,7 +49,6 @@ comment-->
def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
<!-- hello -->
@ -67,7 +66,6 @@ def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None:
def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
<? hello ?>
@ -268,7 +266,6 @@ def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None:
def test_hidden(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
<!DOCTYPE html>

View file

@ -27,7 +27,6 @@ from tests.conftest import reformat
def test_symbol_entities(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,

View file

@ -89,7 +89,6 @@ layout: <div><div></div></div>
def test_custom_parser(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---mycustomparser
@ -114,7 +113,6 @@ slug: home
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---
@ -134,7 +132,6 @@ def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---
@ -155,7 +152,6 @@ def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None:
def test_issue_9042_no_empty_line(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---
@ -177,7 +173,6 @@ Test <a href="https://djlint.com">abc</a>.
def test_issue_9042(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---