karatelabs/karate · warning

Failed to load icons sprite

Error message

Failed to load icons sprite: {}

What it means

loadIconsSprite() loads the bundled _icons.svg sprite used by the HTML report shell, caching it (including a cached empty string after failure). If the classpath resource cannot be read, an IOException is logged as a warning and the report renders without the icon sprite.

Solutions

  1. Verify _icons.svg exists in karate-core's report resource root inside the jar on the classpath
  2. Stop stripping *.svg or the report resource package in shade/minimize/proguard config
  3. Test resource loading with getClass().getResourceAsStream() in the same classloading environment
  4. If unavoidable, accept the degraded report (cached "" means icons are simply missing) or ship the sprite on the classpath yourself

Example fix

// build config: keep report resources in shaded jar
<filters>
  <filter>exclude only *.class minimization, keep **/_icons.svg</filter>
</filters>
Defensive patterns

Strategy: fallback

Validate before calling

try (InputStream in = getClass()
        .getResourceAsStream("/io/karatelabs/output/_icons.svg")) {
    if (in == null) logger.warn("_icons.svg not on classpath — report icons will be missing");
}

Try / catch

try {
    cached = loadClasspathResource(RESOURCE_ROOT + "_icons.svg", false);
} catch (IOException e) {
    logger.warn("Failed to load icons sprite: {}", e.getMessage());
    cached = ""; // degrade gracefully
}

Prevention

When it happens

Trigger: IOException from loadClasspathResource(RESOURCE_ROOT + "_icons.svg", false) when shell() builds the report page — the SVG resource is absent from the classpath or unreadable.

Common situations: Running from a shaded/minimized jar where SVG resources were stripped; custom classloader (app servers, Spring Boot nested jars) that cannot see karate-core resources; corrupted installation.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/output/HtmlReportWriter.java:664

                return sb.toString();
            }
        }
    }

    /**
     * Load the icons sprite once per JVM and cache it. Missing sprite is logged
     * at WARN and the splice yields the empty string — the report still renders,
     * just without icons. See {@code _icons.svg} (Heroicons v2, MIT).
     */
    private static String loadIconsSprite() {
        String cached = iconsSprite;
        if (cached != null) {
            return cached;
        }
        try {
            cached = loadClasspathResource(RESOURCE_ROOT + "_icons.svg", false);
        } catch (IOException e) {
            logger.warn("Failed to load icons sprite: {}", e.getMessage());
            cached = "";
        }
        iconsSprite = cached;
        return cached;
    }

    /**
     * Copy static resources (CSS, JS, images) to the res directory.
     * Made public for use by {@link HtmlReportListener}.
     *
     * @param resDir the res directory to copy resources to
     */
    public static void copyStaticResources(Path resDir) throws IOException {
        for (String resourceName : STATIC_RESOURCES) {
            String resourcePath = RESOURCE_ROOT + "res/" + resourceName;
            try (InputStream is = HtmlReportWriter.class.getClassLoader().getResourceAsStream(resourcePath)) {
                if (is != null) {
                    Files.copy(is, resDir.resolve(resourceName), java.nio.file.StandardCopyOption.REPLACE_EXISTING);

View on GitHub (pinned to a22eb90246)