[GH-ISSUE #1107] There is no existing directory at "xxx" and its not buildable: File exists #452

Closed
opened 2026-03-04 02:15:08 +03:00 by kerem · 1 comment
Owner

Originally created by @gladmo on GitHub (Jan 29, 2018).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1107

When i parallel init StreamHandler, I got this exception.

/path/to/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php ;line 157

    ...
    private function createDir()
    {
        // Do not try to create dir if it has already been tried.
        if ($this->dirCreated) {
            return;
        }

        $dir = $this->getDirFromStream($this->url);
        if (null !== $dir && !is_dir($dir)) {
            $this->errorMessage = null;
            set_error_handler(array($this, 'customErrorHandler'));
            $status = mkdir($dir, 0777, true);
            restore_error_handler();
            if (false === $status) {
                throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: '.$this->errorMessage, $dir));
            }
        }
        $this->dirCreated = true;
    }
    ...

when file exist, mkdir return false, and throw Warning.

I think, when the file is existed, createDir() skip exception UnexpectedValueException will fix this problem. If this is a problem, it can do something in customErrorHandler().

/path/to/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php ;line 133

    private function customErrorHandler($code, $msg)
    {
        // when msg is File exist, do something
        $this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg);
    }
Originally created by @gladmo on GitHub (Jan 29, 2018). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1107 When i parallel init StreamHandler, I got this exception. [/path/to/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php ;line 157](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/StreamHandler.php) ``` php ... private function createDir() { // Do not try to create dir if it has already been tried. if ($this->dirCreated) { return; } $dir = $this->getDirFromStream($this->url); if (null !== $dir && !is_dir($dir)) { $this->errorMessage = null; set_error_handler(array($this, 'customErrorHandler')); $status = mkdir($dir, 0777, true); restore_error_handler(); if (false === $status) { throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: '.$this->errorMessage, $dir)); } } $this->dirCreated = true; } ... ``` when file exist, mkdir return false, and throw Warning. I think, when the file is existed, createDir() skip exception UnexpectedValueException will fix this problem. If this is a problem, it can do something in customErrorHandler(). [/path/to/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php ;line 133](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/StreamHandler.php) ```php private function customErrorHandler($code, $msg) { // when msg is File exist, do something $this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg); } ```
kerem closed this issue 2026-03-04 02:15:08 +03:00
Author
Owner

@Seldaek commented on GitHub (Jun 17, 2018):

Fixed by github.com/Seldaek/monolog@c0eeca76fd

<!-- gh-comment-id:397889513 --> @Seldaek commented on GitHub (Jun 17, 2018): Fixed by https://github.com/Seldaek/monolog/commit/c0eeca76fdb1b5410e7af36bbfe5af265eeb5bf6
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#452
No description provided.