karatelabs/karate · warning
Failed to clean: karate-temp
Error message
Failed to clean: karate-temp
What it means
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.
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
Example fix
// before karate clean # Failed to clean: karate-temp // after (unix) lsof +D karate-temp # find holder, stop it rm -rf ./karate-temp && karate clean
Defensive patterns
Strategy: validation
Validate before calling
// before karate clean (unix) if [ -d karate-temp ]; then lsof +D karate-temp || true; fi rm -rf karate-temp 2>/dev/null || echo 'delete manually'
Try / catch
karate clean 2>&1 | grep -q 'Failed to clean: karate-temp' && (lsof +D karate-temp; exit 1) || true
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to clean:
- 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/2eca8e6d3027f0ad.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/cli/CleanCommand.java:154
} 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"));
}
}
if (cleanedCount == 0) {
Console.println(Console.info("Nothing to clean"));
}
return 0;
}
private void loadPom() {
String file = pomFile != null ? pomFile : RunCommand.DEFAULT_POM_FILE;
Path pomPath;
// If workdir specified, look for pom there
if (workingDir != null) {
pomPath = Path.of(workingDir).resolve(file);
} else {View on GitHub (pinned to a22eb90246)