{"record":{"id":"8708a44debedfc7a","repo":"lcobucci/jwt","slug":"the-path-path-does-not-contain-a-valid-key-file","errorCode":null,"errorMessage":"The path \"{path}\" does not contain a valid key file","messagePattern":"The path \"(.+?)\" does not contain a valid key file","errorType":"exception","errorClass":"Lcobucci\\JWT\\Signer\\Key\\FileCouldNotBeRead","httpStatus":null,"severity":"error","filePath":"src/Signer/Key/InMemory.php","lineNumber":69,"sourceCode":"        self::guardAgainstEmptyKey($decoded); // @phpstan-ignore staticMethod.alreadyNarrowedType\n\n        return new self($decoded, $passphrase);\n    }\n\n    /**\n     * @param non-empty-string $path\n     *\n     * @throws FileCouldNotBeRead\n     */\n    public static function file(\n        string $path,\n        #[SensitiveParameter]\n        string $passphrase = '',\n    ): self {\n        try {\n            $file = new SplFileObject($path);\n        } catch (Throwable $exception) {\n            throw FileCouldNotBeRead::onPath($path, $exception);\n        }\n\n        $fileSize = $file->getSize();\n        $contents = $fileSize > 0 ? $file->fread($file->getSize()) : '';\n        assert(is_string($contents));\n\n        self::guardAgainstEmptyKey($contents);\n\n        return new self($contents, $passphrase);\n    }\n\n    /** @phpstan-assert non-empty-string $contents */\n    private static function guardAgainstEmptyKey(string $contents): void\n    {\n        if ($contents === '') {\n            throw InvalidKeyProvided::cannotBeEmpty();\n        }\n    }","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/lcobucci/jwt/blob/375813049c24c7111bda8b6884c57b071ceb2fe7/src/Signer/Key/InMemory.php#L51-L87","documentation":"Thrown by InMemory::file() when the given path cannot be opened as a key file — typically because the file does not exist or is not readable. The underlying SplFileObject/IO failure is wrapped via FileCouldNotBeRead::onPath().","triggerScenarios":"Calling InMemory::file('/path/to/key.pem') where the path does not exist, is a directory, or the process lacks read permission; also resolving 'file://' key references (e.g. docker secrets paths) that were not mounted.","commonSituations":"Docker/K8s secret file not mounted at the expected path, relative path resolved from a different working directory, wrong filename or typo, file permissions after deployment.","solutions":["Verify the file exists at the exact absolute path: `ls -l /path/to/key.pem`","Check read permissions for the process user (`chmod 644` or fix ownership)","Mount the secret volume correctly (Docker/K8s) before the app starts","Use an absolute path instead of a relative one to avoid CWD surprises"],"exampleFix":"// before\n$key = InMemory::file('keys/private.pem'); // depends on CWD\n// after\n$key = InMemory::file(__DIR__ . '/keys/private.pem');","handlingStrategy":"validation","validationCode":"if (!is_file($path) || !is_readable($path)) { throw new RuntimeException(\"Key file missing or unreadable: $path\"); }","typeGuard":null,"tryCatchPattern":"try { $key = InMemory::file($path); } catch (\\Jose\\Component\\Core\\Exception\\FileCouldNotBeRead $e) { /* log path + prior exception; fail fast */ }","preventionTips":["Use absolute paths resolved with __DIR__ or a config base path","Check secret mounts (Docker/K8s) before app start","Include the path in startup health checks"],"tags":["file","key","path","filesystem"],"backgroundTag":"file-not-found","analyzedSha":"375813049c24c7111bda8b6884c57b071ceb2fe7","analyzedAt":"2026-09-14T11:12:28.004Z","contentChangedAt":"2026-09-14T11:12:28.004Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}