{"record":{"id":"cc27d6b2aa2a5c2c","repo":"usebruno/bruno","slug":"invalid-arguments-passed-to-setcookie","errorCode":null,"errorMessage":"Invalid arguments passed to setCookie","messagePattern":"Invalid arguments passed to setCookie","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-requests/src/cookies/index.ts","lineNumber":335,"sourceCode":"\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();\n          callback(undefined);\n        } catch (err) {\n          callback(err as Error);\n        }\n        return;\n      }\n\n      // Promise mode\n      return new Promise<void>((resolve, reject) => {\n        try {\n          executeSetCookie();\n          resolve();","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-requests/src/cookies/index.ts#L317-L353","documentation":"Thrown by setCookie when nameOrCookieObj is neither a string nor a non-null object — i.e. it is null, a number, an array, a boolean, etc. This is the fallthrough after CASE 1 and CASE 2 fail to match.","triggerScenarios":"Calling setCookie(url, null, ...), setCookie(url, undefined, ...), setCookie(url, 42), or setCookie(url, ['a','b']). The argument-type contract is violated.","commonSituations":"Caller passed a variable that was expected to be a string/object but resolved to null (e.g. JSON.parse returned null); array passed instead of a single cookie object; bug in caller argument wiring.","solutions":["Pass either a string cookie name or a non-null cookie object as the second argument.","Null-check the variable before calling setCookie.","If you have an array, use setCookies instead."],"exampleFix":"// before\ncookieJar.setCookie(url, maybeCookie);  // maybeCookie is null | string | object\n\n// after\nif (maybeCookie == null) return;\nif (Array.isArray(maybeCookie)) {\n  cookieJar.setCookies(url, maybeCookie);\n} else {\n  cookieJar.setCookie(url, maybeCookie);\n}","handlingStrategy":"type-guard","validationCode":"if (typeof nameOrCookieObj !== 'string' && (typeof nameOrCookieObj !== 'object' || nameOrCookieObj === null || Array.isArray(nameOrCookieObj))) {\n  throw new TypeError('setCookie expects a string name or a cookie object');\n}","typeGuard":"function isCookieArg(a) {\n  return typeof a === 'string'\n    || (typeof a === 'object' && a !== null && !Array.isArray(a));\n}","tryCatchPattern":"try { cookieJar.setCookie(url, arg); }\ncatch (e) { if (e.message === 'Invalid arguments passed to setCookie') { /* coerce or skip */ } else throw e; }","preventionTips":["Null-check variables sourced from JSON.parse before passing to setCookie.","Route arrays to setCookies, not setCookie.","Type the wrapper function so the compiler rejects bad arg types."],"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"}