{"record":{"id":"a033c3ecc3e0b421","repo":"karatelabs/karate","slug":"failed-to-clean","errorCode":null,"errorMessage":"Failed to clean: ","messagePattern":"Failed to clean: ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/cli/CleanCommand.java","lineNumber":137,"sourceCode":"        Path parent = output.getParent();\n        if (parent == null) {\n            parent = Path.of(\".\");\n        }\n        String backupPrefix = outputDirName + \"_\";\n\n        try {\n            File parentDir = parent.toFile();\n            File[] backupDirs = parentDir.listFiles((dir, name) ->\n                    name.startsWith(backupPrefix) && new File(dir, name).isDirectory());\n\n            if (backupDirs != null) {\n                for (File backupDir : backupDirs) {\n                    try {\n                        deleteDirectory(backupDir);\n                        Console.println(Console.info(\"Cleaned: \" + backupDir.getName()));\n                        cleanedCount++;\n                    } catch (Exception e) {\n                        Console.println(Console.warn(\"Failed to clean: \" + backupDir.getName()));\n                    }\n                }\n            }\n        } catch (Exception e) {\n            // Ignore errors when scanning for backups\n        }\n\n        // Clean karate-temp directory (Chrome user data, caches, etc.)\n        // Located at <buildDir>/karate-temp (sibling to karate-reports)\n        Path tempDir = parent.resolve(\"karate-temp\");\n        if (Files.exists(tempDir) && Files.isDirectory(tempDir)) {\n            try {\n                deleteDirectory(tempDir.toFile());\n                Console.println(Console.info(\"Cleaned: karate-temp\"));\n                cleanedCount++;\n            } catch (Exception e) {\n                Console.println(Console.warn(\"Failed to clean: karate-temp\"));\n            }","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/cli/CleanCommand.java#L119-L155","documentation":"The `karate clean` CLI deletes leftover backup directories (made during prior cleans) and reports per-directory failures as a warning: 'Failed to clean: <dirname>'. The underlying exception is swallowed, so the command keeps cleaning other directories and only the console message indicates trouble. It is a soft failure, not a thrown error.","triggerScenarios":"Running `karate clean` when a backup directory (e.g. a previously renamed target/output dir) cannot be deleted — files locked by another process, read-only permissions, or an OS-level delete failure inside deleteDirectory().","commonSituations":"Windows users with an editor, Maven daemon, or test process still holding files open in the backup dir; running without write permission on the workspace; stale backups from an aborted earlier run.","solutions":["Close processes holding files in the named backup directory, then rerun `karate clean`","Manually delete the backup directory (rm -rf / rmdir /s /q)","Check and fix directory/file permissions before rerunning","Run the command as a user with write access to the workspace"],"exampleFix":"// before (locked dir)\nkarate clean  # Failed to clean: target-backup\n// after (unix)\nrm -rf ./target-backup && karate clean","handlingStrategy":"validation","validationCode":"// before karate clean (unix)\nif [ -d target-backup ]; then lsof +D target-backup || true; fi\n[ -w . ] && echo \"workspace writable\"","typeGuard":null,"tryCatchPattern":"// wrapper script\nkarate clean 2>&1 | grep -q 'Failed to clean' && echo 'manual cleanup needed' || true","preventionTips":["Stop running Karate/Maven processes before cleaning","Close IDEs/editors locking workspace files (Windows)","Check directory write permissions before running clean","Clean from the workspace owner account, not a restricted service user"],"tags":["cli","filesystem","cleanup","file-lock"],"backgroundTag":"file-delete-failed","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}