Skip to content

Commit ea67770

Browse files
committed
Fix: Better handling of wrong usage
1. Require "documents" in the main config file Accidentally running `bake` with a document config file was just leading to no documents to process and seemingly successful no-op. 2. Only try to remove build directory if it exists Was wrongly assuming non-empty though it never was created
1 parent 637a5f5 commit ea67770

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/pdfbaker/baker.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ def _load_config(self, config_file: Path) -> dict[str, Any]:
7272
"""Load configuration from YAML file."""
7373
try:
7474
with open(config_file, encoding="utf-8") as f:
75-
return yaml.safe_load(f)
75+
config = yaml.safe_load(f)
76+
if "documents" not in config:
77+
raise errors.PDFBakeError(
78+
'Not a main configuration file - "documents" key missing'
79+
)
80+
return config
7681
except Exception as exc:
7782
raise errors.PDFBakeError(f"Failed to load config file: {exc}") from exc
7883

@@ -115,11 +120,12 @@ def _teardown_build_directories(self, doc_names: list[str]) -> None:
115120
doc_build_dir,
116121
)
117122

118-
# Try to remove the base build directory if empty
119-
try:
120-
self.build_dir.rmdir()
121-
except OSError:
122-
# Directory not empty
123-
self.logger.warning(
124-
"Build directory not empty, keeping: %s", self.build_dir
125-
)
123+
# Try to remove the base build directory if it exists and is empty
124+
if self.build_dir.exists():
125+
try:
126+
self.build_dir.rmdir()
127+
except OSError:
128+
# Directory not empty
129+
self.logger.warning(
130+
"Build directory not empty, keeping: %s", self.build_dir
131+
)

0 commit comments

Comments
 (0)