karatelabs/karate · warning

[callSingle] disk cache write failed

Error message

[callSingle] disk cache write failed: {} - {}

What it means

After a successful callSingle execution, Karate attempted to persist the JSON-like result to the disk cache but an IOException occurred while creating directories or writing the file. The run continues — the result is still cached in memory and returned — only cross-JVM/next-run caching is lost for this entry.

Solutions

  1. Check the '{}' detail (I/O error) and fix filesystem access: make the cache directory writable or free disk space.
  2. Point the callSingle cache to a writable location (working directory / temp dir the user can write).
  3. Pre-create the cache directory with correct permissions in CI before the run.
  4. Ignore the warning if disk persistence is not needed — in-memory caching still works.

Example fix

// before
cache dir: target/karate.callSingle (read-only in CI)
// after
chmod -R u+w target/ || export KARATE_CALLSINGLE_DIR=/tmp/karate-cache
Defensive patterns

Strategy: fallback

Validate before calling

File dir = cacheFile.getParentFile();
if (!dir.canWrite()) logger.warn("cache dir not writable: {}", dir);

Try / catch

try { Files.writeString(cacheFile.toPath(), json); } catch (IOException e) { logger.warn("[callSingle] disk cache write failed: {} - {}", cacheFile, e.getMessage()); /* proceed with in-memory cache */ }

Prevention

When it happens

Trigger: Files.writeString or cacheFile.getParentFile().mkdirs() throws IOException in ScenarioRuntime's callSingle disk-cache write path (read-only directory, missing permissions, disk full).

Common situations: CI container with read-only target/; running from a JAR with cwd not writable; disk quota exceeded; multiple concurrent JVMs racing on the cache directory.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/f252ed48c1382de1. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java:785

                    logger.warn("[callSingle] caching exception for: {} - {}", path, e.getMessage());
                    cache.put(path, new CallSingleException(e));
                    throw e;
                }

                long execTime = System.currentTimeMillis() - startExec;
                logger.info("[callSingle] << executed in {}ms: {}", execTime, path);

                // Write to disk cache if configured and result is JSON-like
                if (cacheMinutes > 0 && cacheFile != null) {
                    String notJsonLike = Json.isMapOrList(result) ? findNonJsonValue(result, "$") : "the result itself";
                    if (notJsonLike == null) {
                        try {
                            cacheFile.getParentFile().mkdirs();
                            String json = StringUtils.formatJson(result, false, false, false);
                            Files.writeString(cacheFile.toPath(), json);
                            logger.info("[callSingle] disk cache write: {}", cacheFile);
                        } catch (IOException e) {
                            logger.warn("[callSingle] disk cache write failed: {} - {}", cacheFile, e.getMessage());
                        }
                    } else {
                        logger.warn("[callSingle] disk cache skipped (not JSON-like at {}): {}", notJsonLike, path);
                    }
                }
            }

            // Cache in memory
            cache.put(path, result);
            logger.debug("[callSingle] memory cached: {}", path);

            return StepUtils.deepCopy(result);
        } finally {
            lock.unlock();
        }
    }

    /**

View on GitHub (pinned to a22eb90246)