{"record":{"id":"8c45a520a50a87c4","repo":"zloirock/core-js","slug":"dynamic-url-parse-failure-message-dynamic-thro","errorCode":null,"errorMessage":"<dynamic URL parse failure message> (dynamic: throw new TypeError(failure))","messagePattern":"<dynamic URL parse failure message> \\(dynamic: throw new TypeError\\(failure\\)\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/web.url.constructor.js","lineNumber":431,"sourceCode":"var AUTHORITY = {};\nvar HOST = {};\nvar HOSTNAME = {};\nvar PORT = {};\nvar FILE = {};\nvar FILE_SLASH = {};\nvar FILE_HOST = {};\nvar PATH_START = {};\nvar PATH = {};\nvar CANNOT_BE_A_BASE_URL_PATH = {};\nvar QUERY = {};\nvar FRAGMENT = {};\n\nvar URLState = function (url, isBase, base) {\n  var urlString = $toString(url);\n  var baseState, failure, searchParams;\n  if (isBase) {\n    failure = this.parse(urlString);\n    if (failure) throw new TypeError(failure);\n    this.searchParams = null;\n  } else {\n    if (base !== undefined) baseState = new URLState(base, true);\n    failure = this.parse(urlString, null, baseState);\n    if (failure) throw new TypeError(failure);\n    searchParams = getInternalSearchParamsState(new URLSearchParams());\n    searchParams.bindURL(this);\n    this.searchParams = searchParams;\n  }\n};\n\nURLState.prototype = {\n  type: 'URL',\n  // https://url.spec.whatwg.org/#url-parsing\n  // eslint-disable-next-line max-statements -- TODO\n  parse: function (input, stateOverride, base) {\n    var url = this;\n    var state = stateOverride || SCHEME_START;","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/web.url.constructor.js#L413-L449","documentation":"TypeError raised in the URLState constructor (the internal state behind the URL polyfill) when parsing a URL as a base: this.parse(urlString) returns a failure string produced by the internal URL parser, and any non-null failure is thrown as a TypeError. It means the first argument is not a valid absolute URL.","triggerScenarios":"new URL('not a url') or new URL('') — the string fails the WHATWG URL parser (no scheme, invalid characters, bad IPv4/IPv6 host, etc.); also new URL(url, base) where url is relative but base itself is valid — that path throws at line 436, not here.","commonSituations":"User-supplied or API-returned strings that are not absolute URLs; empty strings from config/env; URLs with spaces or unencoded characters; concatenating strings and forgetting the scheme ('example.com/x' without 'https://').","solutions":["Validate/normalize the URL string before constructing: check it has a scheme or use URL.canParse() where available","Prepend a default scheme when the input lacks one (e.g. 'https://' + host)","Wrap construction in try/catch and surface a friendlier error","Trim whitespace and encode illegal characters first"],"exampleFix":"// before\nconst url = new URL(userInput); // TypeError on 'example.com/page'\n// after\nconst raw = /^\\w+:\\/\\//.test(userInput) ? userInput : 'https://' + userInput;\nconst url = new URL(raw);","handlingStrategy":"try-catch","validationCode":"function safeURL(input, base) {\n  if (typeof input !== 'string' || input.trim() === '') throw new Error('URL required');\n  if (typeof URL.canParse === 'function' && !URL.canParse(input)) throw new Error('Not an absolute URL: ' + input);\n  return new URL(input, base);\n}","typeGuard":"const looksAbsolute = (s) =>\n  typeof s === 'string' && /^[a-zA-Z][a-zA-Z\\d+\\-.]*:/.test(s.trim());","tryCatchPattern":"let url;\ntry {\n  url = new URL(input);\n} catch (e) {\n  if (e instanceof TypeError) {\n    url = new URL('https://' + input.replace(/^\\/+/, ''));\n  } else throw e;\n}","preventionTips":["Validate the scheme exists before new URL(input)","Trim user input and reject empty strings","Use URL.canParse to pre-check on modern engines","Never concatenate URLs without encoding components"],"tags":["url","parse-error","typeerror","polyfill"],"backgroundTag":"invalid-url","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}