{"record":{"id":"f5834e3767fd21e7","repo":"apache/cassandra","slug":"couldn-t-write-stats-html","errorCode":null,"errorMessage":"Couldn't write stats html.","messagePattern":"Couldn't write stats html\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/stress/StressGraph.java","lineNumber":96,"sourceCode":"            }\n            stats = this.createJSONStats(stats);\n        }\n        else\n        {\n            stats = this.createJSONStats(null);\n        }\n\n        try\n        {\n            PrintWriter out = new PrintWriter(htmlFile);\n            String statsBlock = \"/* stats start */\\nstats = \" + JsonUtils.writeAsJsonString(stats) + \";\\n/* stats end */\\n\";\n            String html = getGraphHTML().replaceFirst(\"/\\\\* stats start \\\\*/\\n\\n/\\\\* stats end \\\\*/\\n\", statsBlock);\n            out.write(html);\n            out.close();\n        }\n        catch (IOException e)\n        {\n            throw new RuntimeException(\"Couldn't write stats html.\");\n        }\n    }\n\n    private ObjectNode parseExistingStats(String html)\n    {\n        Pattern pattern = Pattern.compile(\"(?s).*/\\\\* stats start \\\\*/\\\\nstats = (.*);\\\\n/\\\\* stats end \\\\*/.*\");\n        Matcher matcher = pattern.matcher(html);\n        matcher.matches();\n        try\n        {\n            return (ObjectNode) JsonUtils.JSON_OBJECT_MAPPER.readTree(matcher.group(1));\n        }\n        catch (IOException e)\n        {\n            throw new RuntimeException(\"Couldn't parser stats json: \"+e.getMessage(), e);\n        }\n    }\n","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/stress/StressGraph.java#L78-L114","documentation":"StressGraph.generateGraph wraps IOExceptions from writing the final HTML report (opening the writer, writing, or closing) into a RuntimeException 'Couldn't write stats html.' It is thrown after substituting the computed stats block into the graph HTML template. The underlying IOException cause is dropped, hiding whether it was a permission issue, missing directory, or disk-full condition.","triggerScenarios":"Calling generateGraph (via the stress graph option) when the output html file cannot be created or written: unwritable directory, read-only filesystem, invalid path, or an I/O error mid-write (out.write(html) / out.close()).","commonSituations":"Writing the graph into a directory that does not exist; running the stress tool as a user without write access to the output location; disk quota exceeded on CI machines; output path on a read-only mount.","solutions":["Check the output directory exists and is writable by the user running cassandra-stress.","Free disk space or resolve quota/permission issues on the target filesystem.","Write the report to a different, writable location and rerun the graph step.","Patch the catch to include the target file and the cause: new RuntimeException(\"Couldn't write stats html: \" + htmlFile, e)."],"exampleFix":"// before\ncatch (IOException e)\n{\n    throw new RuntimeException(\"Couldn't write stats html.\");\n}\n// after\ncatch (IOException e)\n{\n    throw new RuntimeException(\"Couldn't write stats html: \" + htmlFile, e);\n}","handlingStrategy":"validation","validationCode":"java.io.File out = htmlFile; if (out == null || out.getParentFile() == null || !out.getParentFile().isDirectory() || !out.getParentFile().canWrite()) throw new IllegalArgumentException(\"Cannot write graph html to: \" + out);","typeGuard":null,"tryCatchPattern":"try { generateGraph(); } catch (RuntimeException e) { if (e.getMessage().contains(\"Couldn't write stats html\")) System.err.println(\"Check output dir permissions/disk space\"); throw e; }","preventionTips":["Ensure the output directory exists and is writable by the stress process user.","Monitor disk space/quota on machines producing reports.","Avoid read-only mounts for graph output paths."],"tags":["io","file-write","stress-graph"],"backgroundTag":"file-write-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}