{"record":{"id":"e6abcd77bb333d92","repo":"dianping/cat","slug":"fail-to-create-directory-s","errorCode":null,"errorMessage":"Fail to create directory(%s)!","messagePattern":"Fail to create directory\\((.+?)\\)!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"cat-core/src/main/java/com/dianping/cat/report/LocalReportBucket.java","lineNumber":168,"sourceCode":"\t@Override\n\tpublic void initialize(String name, Date timestamp, int index) throws IOException {\n\t\tm_baseDir = new File(Cat.getCatHome(), \"bucket/report\");\n\t\tm_writeLock = new ReentrantLock();\n\t\tm_readLock = new ReentrantLock();\n\n\t\tString logicalPath = m_pathBuilder.getReportPath(name, timestamp, index);\n\n\t\tFile dataFile = new File(m_baseDir, logicalPath);\n\t\tFile indexFile = new File(m_baseDir, logicalPath + \".idx\");\n\n\t\tif (indexFile.exists()) {\n\t\t\tloadIndexes(indexFile);\n\t\t}\n\n\t\tfinal File dir = dataFile.getParentFile();\n\n\t\tif (!dir.exists() && !dir.mkdirs()) {\n\t\t\tthrow new IOException(String.format(\"Fail to create directory(%s)!\", dir));\n\t\t}\n\n\t\tm_logicalPath = logicalPath;\n\t\tm_writeDataFile = new BufferedOutputStream(new FileOutputStream(dataFile, true), 8192);\n\t\tm_writeIndexFile = new BufferedOutputStream(new FileOutputStream(indexFile, true), 8192);\n\t\tm_writeDataFileLength = dataFile.length();\n\t\tm_readDataFile = new RandomAccessFile(dataFile, \"r\");\n\t}\n\n\tprotected void loadIndexes(File indexFile) throws IOException {\n\t\tBufferedReader reader = null;\n\t\tm_writeLock.lock();\n\t\ttry {\n\t\t\treader = new BufferedReader(new FileReader(indexFile));\n\t\t\tStringSplitter splitter = Splitters.by('\\t');\n\n\t\t\twhile (true) {\n\t\t\t\tString line = reader.readLine();","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-core/src/main/java/com/dianping/cat/report/LocalReportBucket.java#L150-L186","documentation":"LocalReportBucket throws this IOException when the parent directory of the report data file does not exist and File.mkdirs() fails to create it. This happens during local report storage initialization, when the bucket tries to open dataFile and indexFile under m_baseDir for writing. Because the subsequent FileOutputStream calls would also fail, the constructor aborts immediately with the directory path in the message.","triggerScenarios":"Initializing LocalReportBucket when the CAT storage base directory cannot be created: no write permission on the parent path, the path exists as a regular file, a read-only filesystem, or disk full. Also when the report path builder returns a path whose parent collides with an existing file, or in containers/servers where the CAT home dir is misconfigured.","commonSituations":"Running the CAT client/server under a user without write access to /data/applogs/cat or the configured base dir; Docker images where the volume is mounted read-only; a stale file occupying a directory name; SELinux/AppArmor denying mkdir.","solutions":["Check the directory path printed in the message and create it manually (mkdir -p), then verify ownership","Grant write permission to the process user (chown/chmod) on the base dir, e.g. /data/applogs/cat","If running in a container, ensure the log/report volume is mounted writable","Reconfigure the CAT storage base directory to a writable location if the current one is fixed read-only"],"exampleFix":"# before\n# java process runs as user 'app', /data/applogs/cat owned by root\n\n# after\nsudo mkdir -p /data/applogs/cat\nsudo chown -R app:app /data/applogs/cat","handlingStrategy":"validation","validationCode":"File dir = dataFile.getParentFile();\nif (!dir.exists() && !dir.mkdirs()) {\n    if (!dir.canWrite() || !dir.getParentFile().canWrite()) {\n        throw new IllegalStateException(\"No write permission for \" + dir\n            + \" — fix ownership or change the CAT base dir\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    bucket.initialize(...);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Fail to create directory\")) {\n        // surface an actionable config error rather than crashing report storage\n        logger.error(\"CAT report dir not writable: \" + e.getMessage());\n    } else {\n        throw e;\n    }\n}","preventionTips":["At startup, probe-create the CAT report base directory and fail fast with a clear message","Run the CAT process under a user that owns /data/applogs/cat (or the configured base dir)","In containers, mount the report volume read-write and verify writability in the entrypoint"],"tags":["cat","java","io","filesystem","permissions","local-storage"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}