karatelabs/karate · warning

Error loading config

Error message

Error loading config {}: {}

What it means

During Suite startup Karate tries to load the karate-config.js (or configured path) as a classpath or file resource. A ResourceNotFoundException is silently treated as 'not at this location, try fallbacks', but any other exception is logged as this warning and config loading returns null, so the suite proceeds with no config (or the caller decides).

Solutions

  1. Verify the -Dkarate.config / runner config path points at a readable file, not a directory
  2. Check file permissions on the config file and every directory on its path
  3. Look at the surrounding log output; the warning hides the real exception, so temporarily reproduce with Files.readAllBytes to surface the underlying IO error
  4. Fall back to the default karate-config.js on the classpath and confirm it loads

Example fix

// before: config path is a directory
Runner.path("src/test/java").configDir("src/test/java/config")
// after: point at the config file location (dir containing karate-config.js)
Runner.path("src/test/java").configDir("src/test/java")
Defensive patterns

Strategy: try-catch

Validate before calling

// before launching the suite, verify the config path resolves to a readable file
java.nio.file.Path p = java.nio.file.Path.of(configPath);
if (!java.nio.file.Files.isRegularFile(p) || !java.nio.file.Files.isReadable(p))
    throw new IllegalStateException("unreadable config: " + configPath);

Try / catch

// wrap runner bootstrap
try {
    Runner.path("src/test/java").configDir(cfgDir).parallel(threads);
} catch (RuntimeException e) {
    // Suite logs the warning and returns null config; fail fast here instead
    throw new IllegalStateException("karate config failed to load from " + cfgDir, e);
}

Prevention

When it happens

Trigger: Runner.path(...) / Suite construction with a config path that resolves but throws while being read: unreadable file, IO error reading the resource, an exception thrown while constructing Resource from the path, or malformed classpath entry.

Common situations: karate-config.js exists but the process lacks read permission; config path points at a directory instead of a file; broken symlink; config file locked by another process on Windows.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


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

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/Suite.java:399

    /**
     * Try to load a config file and return the Resource (for debugging support).
     */
    private Resource tryLoadConfigResource(String path, boolean warnIfMissing) {
        // Try the explicit path first. Probing, not loading — karate-base.js and
        // karate-config-<env>.js are absent in most projects, and this runs per Suite, so a miss
        // must not cost an exception.
        try {
            Resource resource = Resource.optional(path);
            if (resource != null && resource.exists()) {
                return resource.isFile() && resource.getPath() != null
                        && resource.getPath().getFileSystem() == java.nio.file.FileSystems.getDefault()
                        ? Resource.from(resource.getPath(), root, classpathRoot)
                        : resource;
            }
        } catch (ResourceNotFoundException e) {
            // Not found at explicit path - continue to fallbacks
        } catch (Exception e) {
            logger.warn("Error loading config {}: {}", path, e.getMessage());
            return null;
        }

        String fileName = configFallbackName(path);
        if (fileName != null) {
            // the working dir, then the boot-declared classpath dir — a served Maven project keeps
            // its karate-config.js under src/test/resources while THE root stays the project dir
            for (Path dir : classpathRoot.equals(workingDir)
                    ? List.of(workingDir) : List.of(workingDir, classpathRoot)) {
                try {
                    Path candidate = dir.resolve(fileName);
                    if (Files.exists(candidate)) {
                        return Resource.from(candidate, root, classpathRoot);
                    }
                } catch (Exception e) {
                    logger.debug("Could not load config from {}: {}", dir, e.getMessage());
                }
            }

View on GitHub (pinned to a22eb90246)