{"record":{"id":"20e09eac6a93c624","repo":"Seldaek/monolog","slug":"failed-to-open-file-for-reading-and-writing-path","errorCode":null,"errorMessage":"Failed to open file for reading and writing: {path}","messagePattern":"Failed to open file for reading and writing: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Monolog/Handler/DeduplicationHandler.php","lineNumber":155,"sourceCode":"\n    /**\n     * @return string The given record serialized as a single line of text\n     */\n    protected function buildDeduplicationStoreEntry(LogRecord $record): string\n    {\n        return $record->datetime->getTimestamp() . ':' . $record->level->getName() . ':' . preg_replace('{[\\r\\n].*}', '', $record->message);\n    }\n\n    private function collectLogs(): void\n    {\n        if (!file_exists($this->deduplicationStore)) {\n            return;\n        }\n\n        $handle = fopen($this->deduplicationStore, 'rw+');\n\n        if (false === $handle) {\n            throw new \\RuntimeException('Failed to open file for reading and writing: ' . $this->deduplicationStore);\n        }\n\n        if (false === flock($handle, LOCK_EX)) {\n            fclose($handle);\n            return;\n        }\n        $validLogs = [];\n\n        $timestampValidity = time() - $this->time;\n\n        while (!feof($handle)) {\n            $log = fgets($handle);\n            if (\\is_string($log) && '' !== $log && substr($log, 0, 10) >= $timestampValidity) {\n                $validLogs[] = $log;\n            }\n        }\n\n        ftruncate($handle, 0);","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/Seldaek/monolog/blob/57eb1028342134e701e77c617565d51b6e5a2a53/src/Monolog/Handler/DeduplicationHandler.php#L137-L173","documentation":"Error \"Failed to open file for reading and writing: {path}\" thrown in Seldaek/monolog.","triggerScenarios":"Thrown at src/Monolog/Handler/DeduplicationHandler.php:155 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"57eb1028342134e701e77c617565d51b6e5a2a53","analyzedAt":"2026-08-17T02:36:30.259Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}