{"record":{"id":"84702a129dd93055","repo":"usebruno/bruno","slug":"cookieobject-key-name-is-required","errorCode":null,"errorMessage":"cookieObject.key (name) is required","messagePattern":"cookieObject\\.key \\(name\\) is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-requests/src/cookies/index.ts","lineNumber":323,"sourceCode":"\n          if (!cookieName) throw new Error('Cookie name is required');\n\n          const cookie = new Cookie(\n            hasHostPrefix(cookieName)\n              ? { key: cookieName, value: cookieValue }\n              : { key: cookieName, value: cookieValue, domain: new URL(url).hostname }\n          );\n\n          cookieJar.setCookieSync(cookie, url, { ignoreError: true });\n          return;\n        }\n\n        // CASE 2: cookie object provided\n        if (typeof nameOrCookieObj === 'object' && nameOrCookieObj !== null) {\n          const obj = { ...(nameOrCookieObj as any) } as any;\n\n          if (!obj.key && obj.name) obj.key = obj.name;\n          if (!obj.key) throw new Error('cookieObject.key (name) is required');\n\n          const defaults = hasHostPrefix(obj.key) ? {} : { domain: new URL(url).hostname };\n          const base = { ...defaults, ...obj } as any;\n\n          const processedCookie = createCookieObj(base);\n          const cookie = new Cookie(processedCookie);\n          cookieJar.setCookieSync(cookie, url, { ignoreError: true });\n          return;\n        }\n\n        // If we reach here, arguments were invalid\n        throw new Error('Invalid arguments passed to setCookie');\n      };\n\n      if (callback) {\n        // Callback mode\n        try {\n          executeSetCookie();","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-requests/src/cookies/index.ts#L305-L341","documentation":"Thrown by setCookie CASE 2 (object form) when the cookie object has neither a 'key' nor a 'name' field. The code first aliases obj.name to obj.key, so providing either works; failing both, it rejects the object.","triggerScenarios":"Calling setCookie(url, { value: 'x', domain: '.example.com' }) — the object has no key or name. Also when the object is something like { expires: ... } with the key field accidentally omitted.","commonSituations":"Cookie object built from a Set-Cookie parser that used a different key (e.g. 'cookieName'); partial object literal; typo like 'Key' or 'keu'.","solutions":["Include a 'key' (or 'name') field on the cookie object.","If the source uses a different field name, map it to 'key' before calling setCookie.","Validate the object has a key/name property at the boundary."],"exampleFix":"// before\ncookieJar.setCookie(url, { value: 'abc', domain: '.example.com' });\n\n// after\ncookieJar.setCookie(url, { key: 'session', value: 'abc', domain: '.example.com' });\n// or equivalently:\ncookieJar.setCookie(url, { name: 'session', value: 'abc', domain: '.example.com' });","handlingStrategy":"type-guard","validationCode":"function normalizeCookieObj(obj) {\n  if (!obj.key && obj.name) obj.key = obj.name;\n  if (!obj.key) throw new Error('Cookie object needs key or name');\n  return obj;\n}\ncookieJar.setCookie(url, normalizeCookieObj(raw));","typeGuard":"function isCookieObjectReady(o) {\n  return o != null && typeof o === 'object' && !Array.isArray(o)\n    && (typeof o.key === 'string' && o.key.length > 0 || typeof o.name === 'string' && o.name.length > 0);\n}","tryCatchPattern":"try { cookieJar.setCookie(url, obj); }\ncatch (e) { if (e.message === 'cookieObject.key (name) is required') { /* set key */ } else throw e; }","preventionTips":["Map parser-specific field names to 'key' before calling setCookie.","Use a single cookie-object builder so all objects have a consistent shape.","Unit-test the builder against a list of expected cookie shapes."],"tags":["cookies","validation","configuration"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}