usebruno/bruno · error · Error

URL is required

Error message

URL is required

What it means

Thrown by setCookie (the single-cookie variant) inside executeSetCookie when the url argument is falsy. The cookie jar needs a URL to bind the cookie's domain and path, so the function refuses to proceed. Note it fires in both callback and promise modes because executeSetCookie runs in both paths.

Source

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

      });
    },

    setCookie: function (
      url: string,
      nameOrCookieObj: string | Record<string, any>,
      valueOrCallback?: string | ((err?: Error | undefined) => void),
      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;
        }

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pass a fully-qualified URL (including protocol) as the first argument.
  2. If constructing the URL dynamically, fall back to a default origin when the dynamic value is empty.
  3. Validate arguments at the boundary before calling setCookie.

Example fix

// before
cookieJar.setCookie(maybeUrl, 'session', token);

// after
if (!maybeUrl) throw new Error('Cannot set cookie: request has no URL');
cookieJar.setCookie(maybeUrl, 'session', token);
Defensive patterns

Strategy: validation

Validate before calling

function setCookieSafe(jar, url, name, value) {
  if (!url) throw new Error('setCookie: url is required');
  return jar.setCookie(url, name, value);
}

Type guard

function isNonEmptyUrl(u) { return typeof u === 'string' && u.length > 0; }

Try / catch

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

Prevention

When it happens

Trigger: Calling setCookie(undefined, 'name', 'value') or setCookie('', cookieObject). Any call where the first positional argument is empty/null/undefined.

Common situations: URL variable computed from a request that had no base URL; cookie applied in a pre-request script where the request URL isn't yet resolved; refactor changed argument order.

Related errors


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