From 2ef98977f9d2418f1655de0e7eae9a94912d0df2 Mon Sep 17 00:00:00 2001 From: June Kim Date: Mon, 11 May 2026 20:32:08 -0700 Subject: [PATCH 1/2] fix: add verbose logging to show which file is being processed Addresses issue #384 by adding log output before attempting to read each file when the --verbose flag is used. This helps users identify which file caused an error, especially when processing many files. Previously, verbose mode only showed files after they were processed. Now it prints "Reading " before processing each file, making it easier to diagnose encoding errors or other file-specific issues (as reported in #383). The implementation: - Adds a print statement in _format_one() before reading the file - Uses relative paths when possible for cleaner output - Only prints when mode.verbose is True - Works in both single-process and multiprocess modes Test added to verify verbose logging shows file paths being processed. --- src/sqlfmt/api.py | 9 +++++++++ tests/unit_tests/test_cli.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/sqlfmt/api.py b/src/sqlfmt/api.py index b009e303..1a102fc7 100755 --- a/src/sqlfmt/api.py +++ b/src/sqlfmt/api.py @@ -234,6 +234,15 @@ def _format_one(path: Path, mode: Mode) -> SqlFormatResult: Runs format_string on the contents of a single file (found at path). Handles potential user errors in formatted code, and returns a SqlfmtResult """ + if mode.verbose: + from sqlfmt.report import display_output + + try: + display_path = path.relative_to(Path.cwd()) + except ValueError: + display_path = path + display_output(f"Reading {display_path}") + source, encoding, utf_bom = _read_path_or_stdin(path, mode) try: formatted = format_string(source, mode) diff --git a/tests/unit_tests/test_cli.py b/tests/unit_tests/test_cli.py index 295c9bb6..c16a1187 100755 --- a/tests/unit_tests/test_cli.py +++ b/tests/unit_tests/test_cli.py @@ -273,3 +273,18 @@ def test_config_does_not_exist( assert results.exit_code == 2 assert "Error: Invalid value for '--config'" in results.stderr assert "does not exist" in results.stderr + + +def test_verbose_logging(sqlfmt_runner: CliRunner, preformatted_dir: Path) -> None: + # Use single-process mode to ensure verbose output is captured by CliRunner + args = f"{preformatted_dir.as_posix()} --verbose --check --no-progressbar --single-process" + results = sqlfmt_runner.invoke(sqlfmt_main, args=args) + assert results.exit_code == 0 + # Verbose mode should print each file being processed + assert "Reading" in results.stderr or "Processing" in results.stderr + # Should see at least one file path in the output + sql_files = list(preformatted_dir.glob("*.sql")) + assert len(sql_files) > 0 + # Check that at least one file path appears in verbose output + file_found = any(f.name in results.stderr for f in sql_files) + assert file_found, f"No file paths found in verbose output: {results.stderr}" From 069cee981eb271a2db952e1e04744be46bb45f02 Mon Sep 17 00:00:00 2001 From: June Kim Date: Mon, 11 May 2026 20:42:37 -0700 Subject: [PATCH 2/2] qa: remove dead "Processing" assertion branch in verbose test The test asserted "Reading" or "Processing" in stderr, but the code only emits "Reading". The "Processing" branch was dead and weakened the test. --- tests/unit_tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_cli.py b/tests/unit_tests/test_cli.py index c16a1187..34229602 100755 --- a/tests/unit_tests/test_cli.py +++ b/tests/unit_tests/test_cli.py @@ -281,7 +281,7 @@ def test_verbose_logging(sqlfmt_runner: CliRunner, preformatted_dir: Path) -> No results = sqlfmt_runner.invoke(sqlfmt_main, args=args) assert results.exit_code == 0 # Verbose mode should print each file being processed - assert "Reading" in results.stderr or "Processing" in results.stderr + assert "Reading" in results.stderr # Should see at least one file path in the output sql_files = list(preformatted_dir.glob("*.sql")) assert len(sql_files) > 0