{"record":{"id":"4433ccd94ead7e99","repo":"withastro/astro","slug":"sessionstoragesaveerror","errorCode":"SessionStorageSaveError","errorMessage":"The session key was not provided.","messagePattern":"The session key was not provided\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/session/runtime.ts","lineNumber":185,"sourceCode":"\t\t}\n\t\tthis.#dirty = true;\n\t}\n\n\t/**\n\t * Sets a session value. The session is created if it does not exist.\n\t */\n\n\tset<T = void, K extends string = keyof App.SessionData | (string & {})>(\n\t\tkey: K,\n\t\tvalue: T extends void\n\t\t\t? K extends keyof App.SessionData\n\t\t\t\t? App.SessionData[K]\n\t\t\t\t: any\n\t\t\t: NoInfer<T>,\n\t\t{ ttl }: { ttl?: number } = {},\n\t) {\n\t\tif (!key) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...SessionStorageSaveError,\n\t\t\t\tmessage: 'The session key was not provided.',\n\t\t\t});\n\t\t}\n\t\t// save a clone of the passed in object so later updates are not\n\t\t// persisted into the store. Attempting to serialize also allows\n\t\t// us to throw an error early if needed.\n\t\tlet cloned: T;\n\t\ttry {\n\t\t\tcloned = unflatten(JSON.parse(stringify(value)));\n\t\t} catch (err) {\n\t\t\tthrow new AstroError(\n\t\t\t\t{\n\t\t\t\t\t...SessionStorageSaveError,\n\t\t\t\t\tmessage: `The session data for ${key} could not be serialized.`,\n\t\t\t\t\thint: 'See the devalue library for all supported types: https://github.com/rich-harris/devalue',\n\t\t\t\t},\n\t\t\t\t{ cause: err },","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/session/runtime.ts#L167-L203","documentation":"AstroSession.set requires a non-empty key string. It throws AstroError code SessionStorageSaveError when the provided key is falsy (empty string or undefined), before any serialization happens.","triggerScenarios":"Calling `Astro.session.set('', value)` or `Astro.session.set(someVar, value)` where someVar resolved to undefined or ''.","commonSituations":"Using a computed key from params/query that is missing; destructuring a value that is undefined; defaulting a key to ''.","solutions":["Validate the key is a non-empty string before calling set.","Default missing keys to a stable non-empty identifier.","Log/guard dynamic keys at the call site."],"exampleFix":"// before\nAstro.session.set(userInput, data);\n// after\nconst key = userInput || 'guest';\nAstro.session.set(key, data);","handlingStrategy":"type-guard","validationCode":"function sessionSet(session, key, value) {\n  if (typeof key !== 'string' || key.length === 0) {\n    throw new Error('session.set requires a non-empty string key');\n  }\n  return session.set(key, value);\n}","typeGuard":"const isValidSessionKey = (key: unknown): key is string =>\n  typeof key === 'string' && key.length > 0;","tryCatchPattern":null,"preventionTips":["Never derive a session key from untrusted input without a fallback.","Default computed keys to a stable non-empty string.","Wrap session.set in a helper that validates the key."],"tags":["session","validation"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}