{"record":{"id":"f98365a8a62878bd","repo":"usebruno/bruno","slug":"url-is-required","errorCode":null,"errorMessage":"URL is required","messagePattern":"URL is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-requests/src/cookies/index.ts","lineNumber":299,"sourceCode":"      });\n    },\n\n    setCookie: function (\n      url: string,\n      nameOrCookieObj: string | Record<string, any>,\n      valueOrCallback?: string | ((err?: Error | undefined) => void),\n      maybeCallback?: (err?: Error | undefined) => void\n    ) {\n      // Determine the callback\n      let callback: ((err?: Error | undefined) => void) | undefined;\n      if (typeof maybeCallback === 'function') {\n        callback = maybeCallback;\n      } else if (typeof valueOrCallback === 'function') {\n        callback = valueOrCallback as (err?: Error | undefined) => void;\n      }\n\n      const executeSetCookie = () => {\n        if (!url) throw new Error('URL is required');\n\n        // CASE 1: name/value pair provided\n        if (typeof nameOrCookieObj === 'string') {\n          const cookieName = nameOrCookieObj;\n          const cookieValue = typeof valueOrCallback === 'string' ? valueOrCallback : '';\n\n          if (!cookieName) throw new Error('Cookie name is required');\n\n          const cookie = new Cookie(\n            hasHostPrefix(cookieName)\n              ? { key: cookieName, value: cookieValue }\n              : { key: cookieName, value: cookieValue, domain: new URL(url).hostname }\n          );\n\n          cookieJar.setCookieSync(cookie, url, { ignoreError: true });\n          return;\n        }\n","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-requests/src/cookies/index.ts#L281-L317","documentation":"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.","triggerScenarios":"Calling setCookie(undefined, 'name', 'value') or setCookie('', cookieObject). Any call where the first positional argument is empty/null/undefined.","commonSituations":"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.","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."],"exampleFix":"// before\ncookieJar.setCookie(maybeUrl, 'session', token);\n\n// after\nif (!maybeUrl) throw new Error('Cannot set cookie: request has no URL');\ncookieJar.setCookie(maybeUrl, 'session', token);","handlingStrategy":"validation","validationCode":"function setCookieSafe(jar, url, name, value) {\n  if (!url) throw new Error('setCookie: url is required');\n  return jar.setCookie(url, name, value);\n}","typeGuard":"function isNonEmptyUrl(u) { return typeof u === 'string' && u.length > 0; }","tryCatchPattern":"try { cookieJar.setCookie(url, name, value); }\ncatch (e) { if (e.message === 'URL is required') { /* resolve URL first */ } else throw e; }","preventionTips":["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."],"tags":["cookies","validation","configuration"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}