CLI: directory input crashes with PermissionError on Windows
Bug
On Windows, passing a directory as source to the CLI (e.g. docling ./input --output ./output) crashes with PermissionError instead of processing the directory contents.
Root cause: pathlib.Path.read_bytes() called on a directory path raises IsADirectoryError on Linux/macOS but PermissionError on Windows. The CLI handler at docling/cli/main.py:657 only catches IsADirectoryError, so the PermissionError propagates as an unhandled exception.
The call chain:
docling_core/utils/file.py:111—local_path.read_bytes()is called on the directory path- On Windows this raises
PermissionError: [Errno 13] Permission denied docling/cli/main.py:657—except IsADirectoryError:never matches on Windows- Unhandled crash
Proof that read_bytes() behaves differently on Windows:
>>> from pathlib import Path
>>> Path('.').read_bytes()
# Linux: IsADirectoryError: [Errno 21] Is a directory: '.'
# Windows: PermissionError: [Errno 13] Permission denied: '.'
Steps to reproduce
- On Windows, create a directory with PDF files:
mkdir input copy *.pdf input\ - Run:
docling ./input --output ./output
Expected behavior
Docling should recursively find and convert all supported files in the directory, as it does on Linux/macOS.
Suggested fix
Either:
- Also catch
PermissionErrorinmain.py:657and checklocal_path.is_dir(), or - Check
Path.is_dir()before callingresolve_source_to_path()to avoid the exception entirely
Full traceback
Traceback (most recent call last):
File "...\docling_core\utils\file.py", line 65, in resolve_source_to_stream
http_url: AnyHttpUrl = TypeAdapter(AnyHttpUrl).validate_python(source)
pydantic_core._pydantic_core.ValidationError: 1 validation error for function-wrap[wrap_val()]
Input should be a valid URL, relative URL without a base [type=url_parsing, input_value='./input', input_type=str]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "...\docling\cli\main.py", line 648, in convert
source = resolve_source_to_path(
File "...\docling_core\utils\file.py", line 163, in resolve_source_to_path
return _resolve_source_to_path(
File "...\docling_core\utils\file.py", line 123, in _resolve_source_to_path
doc_stream = resolve_source_to_stream(source=source, headers=headers)
File "...\docling_core\utils\file.py", line 111, in resolve_source_to_stream
stream = BytesIO(local_path.read_bytes())
PermissionError: [Errno 13] Permission denied: 'input'
Docling version
Docling version: 2.80.0
Docling Core version: 2.70.0
Docling IBM Models version: 3.12.0
Docling Parse version: 5.5.0
Python: cpython-311 (3.11.9)
Platform: Windows-10-10.0.26200-SP0
Python version
Python 3.11.9
Hi @morfeus02! I'm Dosu and I’m helping the docling team.
Thanks for the detailed bug report! Your analysis is spot-on. This is indeed a cross-platform inconsistency where Windows raises PermissionError while Linux/macOS raise IsADirectoryError when read_bytes() is called on a directory.
This is a known pattern of Windows compatibility issues - there's a related Issue #607 documenting similar PermissionError behavior when passing directory paths to doc_converter.convert().
Workaround until this is fixed - explicitly glob for files instead of passing the directory:
docling ./input/*.pdf --output ./output
Or in Python:
files = list(Path("./input").glob("*"))
result = doc_converter.convert_all(source=files)
Your suggested fixes are both valid approaches. The cleanest fix would likely be catching both exceptions in main.py:657:
except (IsADirectoryError, PermissionError):
Though checking Path.is_dir() before calling resolve_source_to_path() would be more explicit and avoid relying on exception types altogether.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
Hi, I've reproduced this and traced the root cause — on Windows Path.read_bytes() on a directory raises PermissionError instead of IsADirectoryError. I've prepared a fix that also catches PermissionError in the CLI handler and a regression test that simulates the Windows behavior. Would be happy to open a PR if that's welcome!