usebruno/bruno · error · Error
Invalid arguments passed to setCookie
Error message
Invalid arguments passed to setCookie
What it means
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.
Source
Thrown at packages/bruno-requests/src/cookies/index.ts:335
// CASE 2: cookie object provided
if (typeof nameOrCookieObj === 'object' && nameOrCookieObj !== null) {
const obj = { ...(nameOrCookieObj as any) } as any;
if (!obj.key && obj.name) obj.key = obj.name;
if (!obj.key) throw new Error('cookieObject.key (name) is required');
const defaults = hasHostPrefix(obj.key) ? {} : { domain: new URL(url).hostname };
const base = { ...defaults, ...obj } as any;
const processedCookie = createCookieObj(base);
const cookie = new Cookie(processedCookie);
cookieJar.setCookieSync(cookie, url, { ignoreError: true });
return;
}
// If we reach here, arguments were invalid
throw new Error('Invalid arguments passed to setCookie');
};
if (callback) {
// Callback mode
try {
executeSetCookie();
callback(undefined);
} catch (err) {
callback(err as Error);
}
return;
}
// Promise mode
return new Promise<void>((resolve, reject) => {
try {
executeSetCookie();
resolve();View on GitHub (pinned to 9bdd81c7bd)
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.
Example fix
// before
cookieJar.setCookie(url, maybeCookie); // maybeCookie is null | string | object
// after
if (maybeCookie == null) return;
if (Array.isArray(maybeCookie)) {
cookieJar.setCookies(url, maybeCookie);
} else {
cookieJar.setCookie(url, maybeCookie);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof nameOrCookieObj !== 'string' && (typeof nameOrCookieObj !== 'object' || nameOrCookieObj === null || Array.isArray(nameOrCookieObj))) {
throw new TypeError('setCookie expects a string name or a cookie object');
} Type guard
function isCookieArg(a) {
return typeof a === 'string'
|| (typeof a === 'object' && a !== null && !Array.isArray(a));
} Try / catch
try { cookieJar.setCookie(url, arg); }
catch (e) { if (e.message === 'Invalid arguments passed to setCookie') { /* coerce or skip */ } else throw e; } Prevention
- 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.
When it happens
Trigger: Calling setCookie(url, null, ...), setCookie(url, undefined, ...), setCookie(url, 42), or setCookie(url, ['a','b']). The argument-type contract is violated.
Common situations: 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.
Related errors
- setCookies expects an array of cookie objects
- minifyJson expects a string or object
- minifyXml expects a string
- ${callback} is not a function
- URL is required
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/cc27d6b2aa2a5c2c.
Report an issue: GitHub.