{"record":{"id":"d7d6203778f6816f","repo":"karatelabs/karate","slug":"session-is-unavailable-no-sessionstore-is-configured-call","errorCode":null,"errorMessage":"session is unavailable: no sessionStore is configured. Call ServerConfig.sessionStore(...) at app startup to enable sessions. Attempted to read session.{name}","messagePattern":"session is unavailable: no sessionStore is configured\\. Call ServerConfig\\.sessionStore\\(\\.\\.\\.\\) at app startup to enable sessions\\. Attempted to read session\\.(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/ServerMarkupContext.java","lineNumber":150,"sourceCode":"            // `if (session) { session.foo }` pattern that would silently skip\n            // the branch when session is null now enters and fails noisily,\n            // pointing the developer at ServerConfig.sessionStore(...).\n            vars.put(\"session\", SessionUnavailableProxy.INSTANCE);\n        }\n        return vars;\n    }\n\n    /**\n     * Placeholder for the {@code session} binding when no sessionStore\n     * is configured. Throws a clear, actionable error on any access.\n     */\n    private static final class SessionUnavailableProxy implements io.karatelabs.js.ObjectLike {\n\n        static final SessionUnavailableProxy INSTANCE = new SessionUnavailableProxy();\n\n        @Override\n        public Object getMember(String name) {\n            throw sessionUnavailable(name, false);\n        }\n\n        @Override\n        public void putMember(String name, Object value) {\n            throw sessionUnavailable(name, true);\n        }\n\n        @Override\n        public void removeMember(String name) {\n            throw sessionUnavailable(name, true);\n        }\n\n        @Override\n        public Map<String, Object> toMap() {\n            throw sessionUnavailable(\"(toMap)\", false);\n        }\n\n        private static RuntimeException sessionUnavailable(String name, boolean write) {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/ServerMarkupContext.java#L132-L168","documentation":"ServerMarkupContext exposes a SessionUnavailableProxy for the 'session' object when no session store is configured on the HTTP server. Any property read or write on that proxy throws this exception explaining that ServerConfig.sessionStore(...) must be called at startup. It converts a would-be null session into a clear, actionable failure inside template/JS evaluation.","triggerScenarios":"Server-side template or JS (e.g. in a Karate mock/HTML page served by the dev server) references session.<name> while the server was built without a sessionStore in ServerConfig.","commonSituations":"Templates using session variables on a server started without session configuration; forgetting sessionStore() when enabling auth/session features; local mock servers that never had sessions set up.","solutions":["Call ServerConfig.sessionStore(...) at app startup to enable sessions before serving pages that use session","Remove or guard session usage in templates when sessions aren't needed (e.g. conditionally render)","If sessions should exist, verify the ServerConfig used to build the server is the intended one"],"exampleFix":"// before\nServerConfig config = new ServerConfig().staticFeatures(true);\n// after\nServerConfig config = new ServerConfig()\n    .sessionStore(new InMemorySessionStore())\n    .staticFeatures(true);","handlingStrategy":"validation","validationCode":"// at server startup, verify sessions are configured before serving templates that use session\nif (serverConfig.getSessionStore() == null) throw new IllegalStateException('session usage requires ServerConfig.sessionStore(...)');\n","typeGuard":null,"tryCatchPattern":"try { var user = session.user; } catch (e) { karate.warn('session unavailable: ' + e); var user = null; }\n","preventionTips":["Always call ServerConfig.sessionStore(...) when templates reference session","Guard session access in templates with a feature check","Keep a startup smoke test hitting session-using pages"],"tags":["http","session","server-config","template"],"backgroundTag":"missing-required-config","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"}