{"record":{"id":"2d86ad67992b6423","repo":"FuelLabs/fuels-ts","slug":"invalid-url","errorCode":"INVALID_URL","errorMessage":"Invalid URL provided.","messagePattern":"Invalid URL provided\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/providers/provider.ts","lineNumber":718,"sourceCode":"        this.cache = new ResourceCache(resourceCacheTTL);\n      } else {\n        this.cache = undefined;\n      }\n    } else {\n      this.cache = new ResourceCache(DEFAULT_RESOURCE_CACHE_TTL);\n    }\n  }\n\n  private static extractBasicAuth(url: string): {\n    url: string;\n    urlWithoutAuth: string;\n    headers: ProviderOptions['headers'];\n  } {\n    let parsedUrl: URL;\n    try {\n      parsedUrl = new URL(url);\n    } catch (error) {\n      throw new FuelError(FuelError.CODES.INVALID_URL, 'Invalid URL provided.', { url }, error);\n    }\n\n    const username = parsedUrl.username;\n    const password = parsedUrl.password;\n    const urlWithoutAuth = `${parsedUrl.origin}${parsedUrl.pathname}`;\n    if (!(username && password)) {\n      return { url, urlWithoutAuth: url, headers: undefined };\n    }\n\n    return {\n      url,\n      urlWithoutAuth,\n      headers: { Authorization: `Basic ${btoa(`${username}:${password}`)}` },\n    };\n  }\n\n  /**\n   * Initialize Provider async stuff","sourceCodeStart":700,"sourceCodeEnd":736,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/providers/provider.ts#L700-L736","documentation":"Thrown by Provider.extractBasicAuth when the constructor's URL argument cannot be parsed by the URL constructor (it throws). This happens before any network call, during provider construction. The original parse error is attached as the cause, and the malformed url is included in metadata.","triggerScenarios":"Constructing new Provider(url) with a string that is not a valid absolute URL: missing protocol, stray characters, whitespace, a relative path, or undefined; passing a URL without a scheme (e.g. 'localhost:4000'); passing a URL with embedded credentials malformed.","commonSituations":"Forgetting the http(s):// scheme when reading a URL from env (e.g. process.env.NODE_URL === 'localhost:4000'); trailing slash/space from env var; copy-paste introduced a unicode character; .env var was undefined and coerced to 'undefined'.","solutions":["Ensure the URL has an explicit scheme: 'http://localhost:4000/v1/graphql'.","Trim whitespace and validate the env value before constructing the Provider.","Wrap construction in a try/catch to surface INVALID_URL with the offending value.","Use new URL(url) yourself first to fail with a clearer message during config loading."],"exampleFix":"// before\nconst provider = new Provider(process.env.NODE_URL); // e.g. 'localhost:4000'\n\n// after — normalize at config time\nconst raw = (process.env.NODE_URL ?? '').trim();\nconst url = /^https?:\\/\\//.test(raw) ? raw : `http://${raw}`;\nnew URL(url); // throws early if still invalid\nconst provider = new Provider(url);","handlingStrategy":"validation","validationCode":"function normalizeProviderUrl(raw: string): string {\n  const trimmed = (raw ?? '').trim();\n  const withScheme = /^https?:\\/\\//i.test(trimmed) ? trimmed : `http://${trimmed}`;\n  new URL(withScheme); // throws if still invalid\n  return withScheme;\n}","typeGuard":"function isValidUrl(url: string): boolean {\n  try { new URL(url); return true; } catch { return false; }\n}","tryCatchPattern":"import { FuelError } from '@fuel-ts/errors';\ntry {\n  const provider = new Provider(url);\n} catch (e) {\n  if (e instanceof FuelError && e.code === FuelError.CODES.INVALID_URL) {\n    // prompt for a corrected URL with explicit scheme\n  }\n  throw e;\n}","preventionTips":["Always include the http:// or https:// scheme in env vars.","Trim and validate env-derived URLs at app startup.","Run new URL(url) early so failures surface in config, not in the Provider."],"tags":["provider","url","config","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}