{"record":{"id":"a2fa72d8f58060b1","repo":"usebruno/bruno","slug":"setcookies-expects-an-array-of-cookie-objects","errorCode":null,"errorMessage":"setCookies expects an array of cookie objects","messagePattern":"setCookies expects an array of cookie objects","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-requests/src/cookies/index.ts","lineNumber":368,"sourceCode":"      return new Promise<void>((resolve, reject) => {\n        try {\n          executeSetCookie();\n          resolve();\n        } catch (err) {\n          reject(err);\n        }\n      });\n    },\n\n    setCookies: function (\n      url: string,\n      cookiesArray: any[],\n      callback?: (err?: Error | undefined) => void\n    ) {\n      const executeSetCookies = () => {\n        if (!url) throw new Error('URL is required');\n        if (!Array.isArray(cookiesArray)) {\n          throw new Error('setCookies expects an array of cookie objects');\n        }\n\n        for (const cookieObject of cookiesArray) {\n          const obj = { ...(cookieObject 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        }\n      };\n\n      if (callback) {","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-requests/src/cookies/index.ts#L350-L386","documentation":"Thrown by setCookies when the second argument is not an array. The function iterates the argument as a list of cookie objects, so a non-array (object, string, null) is rejected up front.","triggerScenarios":"Calling setCookies(url, { key: 'a', value: '1' }) (single object instead of array), or setCookies(url, 'a=1; b=2') (cookie header string instead of array).","commonSituations":"Caller confused setCookie vs setCookies semantics; passed a single cookie object to the plural API; passed a raw Cookie header string expecting it to be parsed.","solutions":["Pass an array of cookie objects: [{key, value, ...}, ...].","For a single cookie, use setCookie instead.","If you have a Cookie header string, parse it into objects first (e.g. via tough-cookie Cookie.parse)."],"exampleFix":"// before\ncookieJar.setCookies(url, { key: 'a', value: '1' });\n\n// after\ncookieJar.setCookies(url, [{ key: 'a', value: '1' }]);","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(cookiesArray)) throw new TypeError('setCookies: second argument must be an array');\ncookieJar.setCookies(url, cookiesArray);","typeGuard":"function isCookieArray(a) { return Array.isArray(a); }","tryCatchPattern":"try { cookieJar.setCookies(url, val); }\ncatch (e) { if (e.message === 'setCookies expects an array of cookie objects') { /* wrap in array */ } else throw e; }","preventionTips":["Use setCookie for a single cookie, setCookies only for arrays.","Parse raw Cookie-header strings into arrays before calling setCookies.","Type the wrapper so non-array inputs are rejected at compile time."],"tags":["cookies","validation","type-error"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}