usebruno/bruno · error · Error

setCookies expects an array of cookie objects

Error message

setCookies expects an array of cookie objects

What it means

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.

Source

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

      return new Promise<void>((resolve, reject) => {
        try {
          executeSetCookie();
          resolve();
        } catch (err) {
          reject(err);
        }
      });
    },

    setCookies: function (
      url: string,
      cookiesArray: any[],
      callback?: (err?: Error | undefined) => void
    ) {
      const executeSetCookies = () => {
        if (!url) throw new Error('URL is required');
        if (!Array.isArray(cookiesArray)) {
          throw new Error('setCookies expects an array of cookie objects');
        }

        for (const cookieObject of cookiesArray) {
          const obj = { ...(cookieObject 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 });
        }
      };

      if (callback) {

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pass an array of cookie objects: [{key, value, ...}, ...].
  2. For a single cookie, use setCookie instead.
  3. If you have a Cookie header string, parse it into objects first (e.g. via tough-cookie Cookie.parse).

Example fix

// before
cookieJar.setCookies(url, { key: 'a', value: '1' });

// after
cookieJar.setCookies(url, [{ key: 'a', value: '1' }]);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Array.isArray(cookiesArray)) throw new TypeError('setCookies: second argument must be an array');
cookieJar.setCookies(url, cookiesArray);

Type guard

function isCookieArray(a) { return Array.isArray(a); }

Try / catch

try { cookieJar.setCookies(url, val); }
catch (e) { if (e.message === 'setCookies expects an array of cookie objects') { /* wrap in array */ } else throw e; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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