From 0261a7b3a6fc861ac8608fb3aeb8ff9217cb5940 Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Thu, 24 Sep 2026 22:38:04 +0200 Subject: [PATCH] feat(exceptions): add DirectoryNotEmptyError Added an OSError subclass for indicating that the directory is not empty. This exception is explicitly handled by the CLI now. --- src/jcloud_docsgen/cli/cli.py | 3 +++ src/jcloud_docsgen/exceptions.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/jcloud_docsgen/cli/cli.py b/src/jcloud_docsgen/cli/cli.py index 1fae4e0..7c7f43e 100644 --- a/src/jcloud_docsgen/cli/cli.py +++ b/src/jcloud_docsgen/cli/cli.py @@ -20,6 +20,7 @@ import argparse import pathlib import sys +from ..exceptions import DirectoryNotEmptyError from .languages.python import VALID_SECTIONS as VALID_PYTHON_SECTIONS __all__ = [ @@ -157,6 +158,8 @@ def main(argv=None) -> int: return error(f'{exc.filename}: not a directory') except IsADirectoryError as exc: return error(f'{exc.filename}: is a directory') + except DirectoryNotEmptyError as exc: + return error(f'{exc.filename}: directory not empty') except FileExistsError as exc: return error(f'{exc.filename}: file already exists') except PermissionError as exc: diff --git a/src/jcloud_docsgen/exceptions.py b/src/jcloud_docsgen/exceptions.py index dc81f2e..d687917 100644 --- a/src/jcloud_docsgen/exceptions.py +++ b/src/jcloud_docsgen/exceptions.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import errno + class NamespaceError(ValueError): """ @@ -101,3 +103,12 @@ class PythonDefinitionError(ValueError): class PythonArgumentStructureError(PythonDefinitionError): ... + + +class DirectoryNotEmptyError(OSError): + """ + Directory is not empty. + """ + + def __init__(self, filename: str | None = None) -> None: + super().__init__(errno.ENOTEMPTY, 'Directory not empty', filename)