diff --git a/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php b/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php index 58038cf..b960f4a 100644 --- a/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php +++ b/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php @@ -53,10 +53,16 @@ public function write($config, $file) */ public function writeContent($file, $content) { - $dir = pathinfo($file, PATHINFO_DIRNAME); - if (!is_dir($dir) && !mkdir($dir, 770, true)) { - throw new Exception('Cannot create directory \''.$dir.'\'.'); + $dir = dirname($file); + + try { + if (!is_dir($dir) && !mkdir($dir, 770, true)) { + throw new Exception("Cannot create directory '$dir' (file: $file)."); + } + } catch (\Exception $e) { + throw new Exception("Cannot create directory '$dir' (file: $file)."); } + if (!file_put_contents($file, $content)) { throw new Exception("Cannot write file '$file'."); }