From c8a860825c1539f4e0b010c2bdba1965c1172296 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 9 Oct 2019 23:23:14 +0200 Subject: [PATCH] error handling while creating output dir --- ansibledoctor/DocumentationGenerator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ansibledoctor/DocumentationGenerator.py b/ansibledoctor/DocumentationGenerator.py index b586ec9..b953bc0 100644 --- a/ansibledoctor/DocumentationGenerator.py +++ b/ansibledoctor/DocumentationGenerator.py @@ -52,10 +52,12 @@ class Generator: self.logger.debug("Ignoring template file: " + relative_file) def _create_dir(self, directory): - if not self.config.config["dry_run"]: - os.makedirs(directory, exist_ok=True) - else: - self.logger.info("Creating dir: " + directory) + if not self.config.config["dry_run"] and not os.path.isdir(directory): + try: + os.makedirs(directory, exist_ok=True) + self.logger.info("Creating dir: " + directory) + except FileExistsError as e: + self.log.sysexit_with_message(str(e)) def _write_doc(self): files_to_overwite = []