karatelabs/karate · error · RuntimeException

session is unavailable: no sessionStore is configured. Call…

Error message

session is unavailable: no sessionStore is configured. Call ServerConfig.sessionStore(...) at app startup to enable sessions. Attempted to read session.(toMap)

What it means

Reading the whole session (toMap, e.g. via iterating or serializing `session` or `karate.info` style access) requires a session store. With none configured, ServerMarkupContext's session binding refuses even the read path and reports "Attempted to read session.(toMap)". The library fails fast rather than returning an empty map, so missing configuration is not silently swallowed.

Solutions

  1. Enable sessions via `ServerConfig.sessionStore(...)` at app startup.
  2. Access only specific variables that are not session-backed, or pass needed values through the request/model map instead.
  3. Remove session introspection/debug code from production templates.

Example fix

// before
console.log(JSON.stringify(session));

// after
config -> config.sessionStore(new InMemorySessionStore())...
// or log a specific non-session model attribute instead
Defensive patterns

Strategy: validation

Validate before calling

// avoid whole-session reads unless the store is present
if (!sessionsEnabled) {
    return {}; // or read specific model attributes instead
}
var snap = session; // safe only when sessionStore configured

Prevention

When it happens

Trigger: Markup or JS that reads `session` as a whole (e.g. `session`, `Object.keys(session)`, JSON.stringify of the session binding) on a server without a sessionStore.

Common situations: Debug templates that dump the session; logging middleware serializing context; apps migrated from frameworks where sessions silently default to empty maps.

Related errors


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

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/http/ServerMarkupContext.java:165

        @Override
        public Object getMember(String name) {
            throw sessionUnavailable(name, false);
        }

        @Override
        public void putMember(String name, Object value) {
            throw sessionUnavailable(name, true);
        }

        @Override
        public void removeMember(String name) {
            throw sessionUnavailable(name, true);
        }

        @Override
        public Map<String, Object> toMap() {
            throw sessionUnavailable("(toMap)", false);
        }

        private static RuntimeException sessionUnavailable(String name, boolean write) {
            return new RuntimeException(
                    "session is unavailable: no sessionStore is configured. "
                            + "Call ServerConfig.sessionStore(...) at app startup to enable sessions. "
                            + "Attempted to " + (write ? "write" : "read") + " session." + name);
        }
    }

    // MarkupContext implementation

    @Override
    public String getTemplateName() {
        return templateName;
    }

    @Override

View on GitHub (pinned to a22eb90246)