karatelabs/karate · warning
Failed to clean:
Error message
Failed to clean:
What it means
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.
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
Example fix
// before (locked dir) karate clean # Failed to clean: target-backup // after (unix) rm -rf ./target-backup && karate clean
Defensive patterns
Strategy: validation
Validate before calling
// before karate clean (unix) if [ -d target-backup ]; then lsof +D target-backup || true; fi [ -w . ] && echo "workspace writable"
Try / catch
// wrapper script karate clean 2>&1 | grep -q 'Failed to clean' && echo 'manual cleanup needed' || true
Prevention
- 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
When it happens
Trigger: 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().
Common situations: 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.
Related errors
- Failed to clean: karate-temp
- Failed to clean output directory:
- Failed to backup existing dir
- Failed to close JSONL event stream
- Failed to copy ext assets for
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/a033c3ecc3e0b421.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/cli/CleanCommand.java:137
Path parent = output.getParent();
if (parent == null) {
parent = Path.of(".");
}
String backupPrefix = outputDirName + "_";
try {
File parentDir = parent.toFile();
File[] backupDirs = parentDir.listFiles((dir, name) ->
name.startsWith(backupPrefix) && new File(dir, name).isDirectory());
if (backupDirs != null) {
for (File backupDir : backupDirs) {
try {
deleteDirectory(backupDir);
Console.println(Console.info("Cleaned: " + backupDir.getName()));
cleanedCount++;
} catch (Exception e) {
Console.println(Console.warn("Failed to clean: " + backupDir.getName()));
}
}
}
} catch (Exception e) {
// Ignore errors when scanning for backups
}
// Clean karate-temp directory (Chrome user data, caches, etc.)
// Located at <buildDir>/karate-temp (sibling to karate-reports)
Path tempDir = parent.resolve("karate-temp");
if (Files.exists(tempDir) && Files.isDirectory(tempDir)) {
try {
deleteDirectory(tempDir.toFile());
Console.println(Console.info("Cleaned: karate-temp"));
cleanedCount++;
} catch (Exception e) {
Console.println(Console.warn("Failed to clean: karate-temp"));
}View on GitHub (pinned to a22eb90246)