{"record":{"id":"0916098c932c8b18","repo":"karatelabs/karate","slug":"error-loading-config","errorCode":null,"errorMessage":"Error loading config {}: {}","messagePattern":"Error loading config (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/core/Suite.java","lineNumber":399,"sourceCode":"    /**\n     * Try to load a config file and return the Resource (for debugging support).\n     */\n    private Resource tryLoadConfigResource(String path, boolean warnIfMissing) {\n        // Try the explicit path first. Probing, not loading — karate-base.js and\n        // karate-config-<env>.js are absent in most projects, and this runs per Suite, so a miss\n        // must not cost an exception.\n        try {\n            Resource resource = Resource.optional(path);\n            if (resource != null && resource.exists()) {\n                return resource.isFile() && resource.getPath() != null\n                        && resource.getPath().getFileSystem() == java.nio.file.FileSystems.getDefault()\n                        ? Resource.from(resource.getPath(), root, classpathRoot)\n                        : resource;\n            }\n        } catch (ResourceNotFoundException e) {\n            // Not found at explicit path - continue to fallbacks\n        } catch (Exception e) {\n            logger.warn(\"Error loading config {}: {}\", path, e.getMessage());\n            return null;\n        }\n\n        String fileName = configFallbackName(path);\n        if (fileName != null) {\n            // the working dir, then the boot-declared classpath dir — a served Maven project keeps\n            // its karate-config.js under src/test/resources while THE root stays the project dir\n            for (Path dir : classpathRoot.equals(workingDir)\n                    ? List.of(workingDir) : List.of(workingDir, classpathRoot)) {\n                try {\n                    Path candidate = dir.resolve(fileName);\n                    if (Files.exists(candidate)) {\n                        return Resource.from(candidate, root, classpathRoot);\n                    }\n                } catch (Exception e) {\n                    logger.debug(\"Could not load config from {}: {}\", dir, e.getMessage());\n                }\n            }","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/Suite.java#L381-L417","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the -Dkarate.config / runner config path points at a readable file, not a directory","Check file permissions on the config file and every directory on its path","Look at the surrounding log output; the warning hides the real exception, so temporarily reproduce with Files.readAllBytes to surface the underlying IO error","Fall back to the default karate-config.js on the classpath and confirm it loads"],"exampleFix":"// before: config path is a directory\nRunner.path(\"src/test/java\").configDir(\"src/test/java/config\")\n// after: point at the config file location (dir containing karate-config.js)\nRunner.path(\"src/test/java\").configDir(\"src/test/java\")","handlingStrategy":"try-catch","validationCode":"// before launching the suite, verify the config path resolves to a readable file\njava.nio.file.Path p = java.nio.file.Path.of(configPath);\nif (!java.nio.file.Files.isRegularFile(p) || !java.nio.file.Files.isReadable(p))\n    throw new IllegalStateException(\"unreadable config: \" + configPath);","typeGuard":null,"tryCatchPattern":"// wrap runner bootstrap\ntry {\n    Runner.path(\"src/test/java\").configDir(cfgDir).parallel(threads);\n} catch (RuntimeException e) {\n    // Suite logs the warning and returns null config; fail fast here instead\n    throw new IllegalStateException(\"karate config failed to load from \" + cfgDir, e);\n}","preventionTips":["Point configDir at a directory containing karate-config.js, never at the file or a random path","Assert the config file exists in a setup/CI preflight step","Check read permissions on the config in containers (run as correct user, copy with correct mode)","Keep a default karate-config.js on the test classpath as fallback"],"tags":["config","startup","resource-loading"],"backgroundTag":"config-file-not-found","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}