karatelabs/karate · warning

Failed to copy static resources

Error message

Failed to copy static resources: {}

What it means

HtmlReportListener.ensureResourcesCopied() copies the report's static resources (CSS/JS) into <outputDir>/res via HtmlReportWriter.copyStaticResources once per suite. If that copy fails for any reason, the listener logs a warning instead of failing the test run — reporting is best-effort by design, so tests still execute but the generated HTML report may be missing styling/scripts.

Solutions

  1. Verify the output directory (karate.outputDir / -Dkarate.outputDir) exists and is writable by the process user
  2. Check free disk space on the volume holding the output directory
  3. If running from a custom/shaded jar, confirm karate-core's report resources under the report resource root are included (check resource filtering/excludes in the build)
  4. Inspect debug-level logs (enable io.karatelabs.output DEBUG) or temporarily re-throw to see the full stack trace

Example fix

// before: opaque message only
logger.warn("Failed to copy static resources: {}", e.getMessage());
// after: surface the root cause during diagnosis
logger.warn("Failed to copy static resources: {}", e.getMessage(), e);
Defensive patterns

Strategy: fallback

Validate before calling

Path res = outputDir.resolve("res");
if (!Files.isWritable(outputDir) || (Files.exists(res) && !Files.isDirectory(res))) {
    throw new IllegalStateException("outputDir not writable for report resources: " + outputDir);
}

Try / catch

try {
    HtmlReportWriter.copyStaticResources(outputDir.resolve("res"));
} catch (Exception e) {
    logger.warn("report will lack static resources", e); // keep run alive, log stack
}

Prevention

When it happens

Trigger: Any exception thrown by HtmlReportWriter.copyStaticResources(Path) when onFeatureEnd or onSuiteEnd first triggers the lazy copy — e.g. the output directory cannot be created or written, classpath resources are missing, or disk is full.

Common situations: Output dir points to a read-only path or one owned by another user; disk full on CI; outputDir deleted or replaced mid-run; running inside a packaged/jlink or shaded jar where the static resources were excluded from the artifact.

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/ac0241174ef59a42. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/output/HtmlReportListener.java:204

            HtmlReportWriter.writeSummaryPages(featureMaps, result, outputDir, env, reportAssets, summaryCards);

            // Write timeline page using canonical feature maps
            HtmlReportWriter.writeTimelineHtml(featureMaps, result, outputDir, env, threadCount, reportAssets);

            logger.debug("HTML report written to: {}", outputDir.resolve("karate-summary.html"));

        } catch (Exception e) {
            logger.warn("Failed to write HTML summary: {}", e.getMessage());
        }
    }

    private synchronized void ensureResourcesCopied() {
        if (!resourcesCopied) {
            try {
                HtmlReportWriter.copyStaticResources(outputDir.resolve("res"));
                resourcesCopied = true;
            } catch (Exception e) {
                logger.warn("Failed to copy static resources: {}", e.getMessage());
            }
        }
    }

}

View on GitHub (pinned to a22eb90246)