{"record":{"id":"2eca8e6d3027f0ad","repo":"karatelabs/karate","slug":"failed-to-clean-karate-temp","errorCode":null,"errorMessage":"Failed to clean: karate-temp","messagePattern":"Failed to clean: karate-temp","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/cli/CleanCommand.java","lineNumber":154,"sourceCode":"                    } 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            }\n        }\n\n        if (cleanedCount == 0) {\n            Console.println(Console.info(\"Nothing to clean\"));\n        }\n\n        return 0;\n    }\n\n    private void loadPom() {\n        String file = pomFile != null ? pomFile : RunCommand.DEFAULT_POM_FILE;\n        Path pomPath;\n\n        // If workdir specified, look for pom there\n        if (workingDir != null) {\n            pomPath = Path.of(workingDir).resolve(file);\n        } else {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/cli/CleanCommand.java#L136-L172","documentation":"The `karate clean` CLI deletes the karate-temp working directory and, if deleteDirectory() fails for any reason, prints 'Failed to clean: karate-temp' as a console warning and continues; the exception is swallowed. Like the backup-dir case it is non-fatal — the command proceeds and reports 'Nothing to clean' only when nothing was removed.","triggerScenarios":"Running `karate clean` while the karate-temp directory exists but cannot be removed — files inside are locked by a running process, permissions deny deletion, or the OS refuses the recursive delete.","commonSituations":"A previous Karate run (mock server, driver session) still alive and writing into karate-temp; antivirus/backup software scanning temp files during cleanup; running the CLI under a restricted service account.","solutions":["Stop any running Karate/mock-server processes, then rerun `karate clean`","Delete the karate-temp directory manually and verify permissions","Check for file locks (Windows: Resource Monitor; Unix: lsof +D karate-temp)","Run the clean step from a context with write permission over the workspace"],"exampleFix":"// before\nkarate clean  # Failed to clean: karate-temp\n// after (unix)\nlsof +D karate-temp   # find holder, stop it\nrm -rf ./karate-temp && karate clean","handlingStrategy":"validation","validationCode":"// before karate clean (unix)\nif [ -d karate-temp ]; then lsof +D karate-temp || true; fi\nrm -rf karate-temp 2>/dev/null || echo 'delete manually'","typeGuard":null,"tryCatchPattern":"karate clean 2>&1 | grep -q 'Failed to clean: karate-temp' && (lsof +D karate-temp; exit 1) || true","preventionTips":["Ensure mock servers/driver sessions are stopped before cleaning","Exclude karate-temp from antivirus/indexer scanning","Run cleanup with sufficient filesystem permissions","Automate cleanup in CI from a fresh workspace to avoid stale locks"],"tags":["cli","filesystem","temp-directory","cleanup"],"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"}