{"record":{"id":"b17992dcc0adfd0e","repo":"karatelabs/karate","slug":"failed-to-backup-existing-dir","errorCode":null,"errorMessage":"Failed to backup existing dir '{}': {}","messagePattern":"Failed to backup existing dir '(.+?)': (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/core/Suite.java","lineNumber":1111,"sourceCode":"            DateTimeFormatter.ofPattern(\"yyyyMMdd_HHmmss\");\n\n    private void backupReportDirIfExists() {\n        if (!Files.exists(outputDir)) {\n            return;\n        }\n        String timestamp = LocalDateTime.now().format(BACKUP_DATE_FORMAT);\n        String baseName = outputDir.getFileName() + \"_\" + timestamp;\n        Path backupPath = outputDir.resolveSibling(baseName);\n        int suffix = 1;\n        while (Files.exists(backupPath)) {\n            backupPath = outputDir.resolveSibling(baseName + \"_\" + suffix);\n            suffix++;\n        }\n        try {\n            Files.move(outputDir, backupPath);\n            logger.info(\"backed up existing output to: {}\", backupPath);\n        } catch (Exception e) {\n            logger.warn(\"Failed to backup existing dir '{}': {}\", outputDir, e.getMessage());\n        }\n    }\n\n    // ========== Accessors (for private fields) ==========\n\n    public String getOutputDir() {\n        return outputDir.toString();\n    }\n\n    public Map<String, Object> getCallSingleCache() {\n        return CALLSINGLE_CACHE;\n    }\n\n    public ReentrantLock getCallSingleLock() {\n        return callSingleLock;\n    }\n\n    /**","sourceCodeStart":1093,"sourceCodeEnd":1129,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/Suite.java#L1093-L1129","documentation":"Before a run, Suite can back up an existing output directory by moving it (Files.move) to a suffixed backup path. If the move fails, this warning is logged and the run proceeds anyway — old output may be overwritten or mixed with new output.","triggerScenarios":"Suite construction (dryRun/cleanup option) where the existing outputDir cannot be moved: the directory is open in another process (e.g. an IDE or file watcher on Windows), permission denied on the parent, or the backup target path is locked/non-writable.","commonSituations":"target/karate-reports open in a browser/IDE on Windows (file locking); CI workspace with leftover read-only artifacts; antivirus scanning the reports directory during the move.","solutions":["Close programs holding the output dir open (IDE report viewer, browser, tail -f) and re-run","Check write permissions on the parent directory of the output dir","Delete the old output dir manually before running","On Windows, exclude the reports dir from antivirus/indexing that can lock files mid-move"],"exampleFix":"// before: run with reports locked by an open viewer\nmvn test -Dkarate.options=\"target/karate-reports\"\n// after: clean the dir first so nothing needs backing up\nmvn clean test","handlingStrategy":"validation","validationCode":"java.nio.file.Path out = java.nio.file.Path.of(outputDir);\nif (java.nio.file.Files.exists(out)) {\n    // ensure we can move it: parent writable and nothing locked\n    if (!java.nio.file.Files.isWritable(out.getParent()))\n        throw new IllegalStateException(\"cannot backup, parent not writable: \" + out.getParent());\n}","typeGuard":null,"tryCatchPattern":"try { new Suite(builder).run(); }\ncatch (Exception e) {\n    // backup failure is only a warning; if stale output matters, verify freshness\n    logger.info(\"run finished; confirm reports are from this run: \" + outputDir);\n}","preventionTips":["Run mvn clean (or delete the reports dir) before CI runs so nothing needs backing up","Keep report viewers/IDE windows on old reports closed on Windows to avoid file locks","Exclude the output dir from antivirus/indexing in dev environments","Run tests as a user with write permission on the workspace"],"tags":["io","filesystem","output"],"backgroundTag":"file-write-failed","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}