{"record":{"id":"417f40b3aa910a95","repo":"karatelabs/karate","slug":"failed-to-load-name","errorCode":null,"errorMessage":"Failed to load {name}","messagePattern":"Failed to load (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":77,"sourceCode":"import java.util.concurrent.TimeUnit;\nimport java.util.function.Supplier;\n\n/**\n * CDP-based browser driver implementation.\n * Implements the Driver interface using Chrome DevTools Protocol.\n */\npublic class CdpDriver implements Driver {\n\n    private static final Logger logger = LogContext.RUNTIME_LOGGER;\n\n    // Karate JS runtime (wildcard resolver, shared utilities)\n    private static final String DRIVER_JS = loadResource(\"driver.js\");\n\n    private static String loadResource(String name) {\n        try (InputStream is = CdpDriver.class.getResourceAsStream(\"/io/karatelabs/driver/\" + name)) {\n            return new String(is.readAllBytes(), StandardCharsets.UTF_8);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to load \" + name, e);\n        }\n    }\n\n    // Track active drivers for cleanup\n    private static final Set<CdpDriver> ACTIVE = ConcurrentHashMap.newKeySet();\n\n    private final CdpClient cdp;\n    private final CdpDriverOptions options;\n    private final CdpLauncher launcher; // null if connected to existing browser\n\n    // Page load state\n    private volatile boolean domContentEventFired;\n    private final Set<String> framesStillLoading = ConcurrentHashMap.newKeySet();\n    // volatile: written on the scenario thread (initialize / activateTarget), read by\n    // every Page.* event handler on the CDP dispatch thread for main-frame filtering\n    private volatile String mainFrameId;\n    private volatile String pendingNavigationUrl; // for better timeout diagnostics\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L59-L95","documentation":"CdpDriver statically loads its bundled driver.js init script from the classpath (/io/karatelabs/driver/driver.js). If the resource stream is null or reading fails, loadResource throws 'Failed to load driver.js'. This is a packaging/classpath corruption problem, not a runtime behavior issue.","triggerScenarios":"karate-core jar is truncated or corrupted in the local Maven cache; a shaded/fat jar excludes the resource; custom classloader that cannot see the karate-core resources; build/packaging misconfiguration dropping resources.","commonSituations":"Corrupted ~/.m2 cache after a failed download; running with a repackaged jar missing resources; IDE/dependency conflicts pulling a broken karate-core artifact; Docker images that strip resources.","solutions":["Delete the karate-core artifact from the local Maven repo and re-download (mvn -U)","Verify the jar contains io/karatelabs/driver/driver.js (unzip -l)","Use the official published karate-core artifact instead of a custom shaded/relocated build","Check the packaging config of any fat jar keeps /io/karatelabs/driver/ resources"],"exampleFix":"// before: corrupted jar\nls ~/.m2/repository/io/karatelabs/karate-core/.../karate-core.jar # truncated\n// after\nrm -rf ~/.m2/repository/io/karatelabs/karate-core\nmvn -U clean test","handlingStrategy":"validation","validationCode":"// pre-check the resource exists before any CdpDriver use\njava.io.InputStream is = CdpDriver.class\n    .getResourceAsStream(\"/io/karatelabs/driver/driver.js\");\nif (is == null) {\n    throw new IllegalStateException(\"karate-core jar missing driver.js — re-download dependencies\");\n}\nis.close();","typeGuard":"null","tryCatchPattern":"try { Driver d = karate.driver; }\ncatch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to load \")) {\n        throw new IllegalStateException(\"Corrupt karate-core jar; run mvn -U after clearing the cache\", e);\n    }\n    throw e;\n}","preventionTips":["Verify karate-core jar integrity after downloads (unzip -l)","Avoid custom shaded builds that strip /io/karatelabs/driver/ resources","Clear ~/.m2 cache entries after failed downloads","Pin known-good karate-core versions"],"tags":["classpath","resource-loading","packaging"],"backgroundTag":"resource-not-found","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}