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.
Solutions
- Pass a fully-qualified URL (including protocol) as the first argument.
- If constructing the URL dynamically, fall back to a default origin when the dynamic value is empty.
- 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
- Resolve the request URL before running pre-request scripts that touch cookies.
- Wrap cookie operations in a helper that asserts the URL is set.
- Test cookie scripts against a request with a concrete base URL.
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
- Cookie name is required
- cookieObject.key (name) is required
- Access token URL is required for OAuth2
- Access Token URL is required for OAuth2 client credentials…
- Access Token URL is required for OAuth2 password…
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/f98365a8a62878bd.
Report an issue: GitHub.
Appendix: 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)