{"record":{"id":"cfd0f9b18be60215","repo":"nodejs/node","slug":"und-err-invalid-arg","errorCode":"UND_ERR_INVALID_ARG","errorMessage":"invalid url","messagePattern":"invalid url","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/index.js","lineNumber":82,"sourceCode":"const SqliteCacheStore = require('./lib/cache/sqlite-cache-store')\nmodule.exports.cacheStores.SqliteCacheStore = SqliteCacheStore\n\nmodule.exports.buildConnector = buildConnector\nmodule.exports.errors = errors\nmodule.exports.util = {\n  parseHeaders: util.parseHeaders,\n  headerNameToString: util.headerNameToString\n}\n\nfunction makeDispatcher (fn) {\n  return (url, opts, handler) => {\n    if (typeof opts === 'function') {\n      handler = opts\n      opts = null\n    }\n\n    if (!url || (typeof url !== 'string' && typeof url !== 'object' && !(url instanceof URL))) {\n      throw new InvalidArgumentError('invalid url')\n    }\n\n    if (opts != null && typeof opts !== 'object') {\n      throw new InvalidArgumentError('invalid opts')\n    }\n\n    if (opts && opts.path != null) {\n      if (typeof opts.path !== 'string') {\n        throw new InvalidArgumentError('invalid opts.path')\n      }\n\n      let path = opts.path\n      if (!opts.path.startsWith('/')) {\n        path = `/${path}`\n      }\n\n      url = new URL(util.parseOrigin(url).origin + path)\n    } else {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/index.js#L64-L100","documentation":"Thrown by undici's makeDispatcher (the wrapper behind request/stream/fetch/pipeline/upgrade/connect/quickLoad) when the url argument is missing or not a string, plain object, or URL instance. Code is UND_ERR_INVALID_ARG. It is a synchronous argument-type guard before any networking occurs.","triggerScenarios":"Calling any undici dispatcher method (request, stream, pipeline, fetch, upgrade, connect) with url = undefined, null, a number, boolean, or any non-string/non-object value.","commonSituations":"Reading URL from an env var or config that is undefined; passing a parsed object that is not a URL; template-literal producing empty string; variable renamed/typo; async source resolved to undefined.","solutions":["Ensure the url argument is a non-empty string or a URL/URL-like object before the call.","Default/validate the value at the call site: const url = process.env.API_URL; if (!url) throw ...","Construct the URL explicitly with new URL(...) upstream so it is always a URL instance.","Check for undefined return from the upstream source of the URL."],"exampleFix":"// before\nawait dispatcher.request(endpoint)        // endpoint is undefined\n// after\nif (!endpoint) throw new Error('endpoint missing')\nawait dispatcher.request(new URL(endpoint))","handlingStrategy":"type-guard","validationCode":"function resolveUrl(u) {\n  if (!u) throw new Error('url required')\n  return typeof u === 'string' || u instanceof URL ? u : new URL(u)\n}","typeGuard":"function isValidUndiciUrl(u: unknown): u is string | URL | Record<string, unknown> {\n  return typeof u === 'string' || u instanceof URL || (typeof u === 'object' && u !== null)\n}","tryCatchPattern":"try {\n  await dispatcher.request(url, opts)\n} catch (err) {\n  if (err.code === 'UND_ERR_INVALID_ARG' && /invalid url/.test(err.message)) {\n    throw new Error(`Invalid request: url argument missing or wrong type (${url})`)\n  }\n  throw err\n}","preventionTips":["Always construct URLs with new URL(...) upstream.","Validate env/config-derived URLs are non-empty strings before passing.","Enable TypeScript and type the url arg as string | URL."],"tags":["undici","validation","url","argument","http"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}