usebruno/bruno · error · Error

Cookie name is required

Error message

Cookie name is required

What it means

Thrown by setCookie when the name/value form is used (nameOrCookieObj is a string) but the string is empty. The branch constructs a Cookie keyed by this name, so an empty key is rejected before reaching the cookie jar.

Source

Thrown at packages/bruno-requests/src/cookies/index.ts:306

      maybeCallback?: (err?: Error | undefined) => void
    ) {
      // Determine the callback
      let callback: ((err?: Error | undefined) => void) | undefined;
      if (typeof maybeCallback === 'function') {
        callback = maybeCallback;
      } else if (typeof valueOrCallback === 'function') {
        callback = valueOrCallback as (err?: Error | undefined) => void;
      }

      const executeSetCookie = () => {
        if (!url) throw new Error('URL is required');

        // CASE 1: name/value pair provided
        if (typeof nameOrCookieObj === 'string') {
          const cookieName = nameOrCookieObj;
          const cookieValue = typeof valueOrCallback === 'string' ? valueOrCallback : '';

          if (!cookieName) throw new Error('Cookie name is required');

          const cookie = new Cookie(
            hasHostPrefix(cookieName)
              ? { key: cookieName, value: cookieValue }
              : { key: cookieName, value: cookieValue, domain: new URL(url).hostname }
          );

          cookieJar.setCookieSync(cookie, url, { ignoreError: true });
          return;
        }

        // 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');

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pass a non-empty cookie name as the second argument.
  2. Double-check argument order: (url, name, value) — not (url, value, name).
  3. Skip the setCookie call when the computed name is empty.

Example fix

// before
cookieJar.setCookie(url, '', 'value123');

// after
cookieJar.setCookie(url, 'session_id', 'value123');
Defensive patterns

Strategy: validation

Validate before calling

if (!name || !name.trim()) throw new Error('Cookie name cannot be empty');
cookieJar.setCookie(url, name, value);

Type guard

function isValidCookieName(n) { return typeof n === 'string' && n.trim().length > 0; }

Try / catch

try { cookieJar.setCookie(url, name, value); }
catch (e) { if (e.message === 'Cookie name is required') { /* pick a name */ } else throw e; }

Prevention

When it happens

Trigger: Calling setCookie(url, '', 'value') — the second argument is an empty string while the third (value) is also a string, selecting CASE 1.

Common situations: Cookie name sourced from a parsed header or variable that resolved to empty; the caller passed value as the second arg by mistake (arg-order confusion).

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/892f51dda215c701. Report an issue: GitHub.