{"record":{"id":"258f647081c81994","repo":"Mintplex-Labs/anything-llm","slug":"no-scheme-found-in-uri-uri","errorCode":null,"errorMessage":"No scheme found in URI ${uri}","messagePattern":"No scheme found in URI (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js","lineNumber":102,"sourceCode":"   * present in the input.\n   * @param {string} uri The connection string URI\n   * @returns {ConnectionStringObject} The connection string object\n   */\n  parse(uri) {\n    const connectionStringParser = new RegExp(\n      \"^\\\\s*\" + // Optional whitespace padding at the beginning of the line\n        \"([^:]+)://\" + // Scheme (Group 1)\n        \"(?:([^:@,/?=&]+)(?::([^:@,/?=&]+))?@)?\" + // User (Group 2) and Password (Group 3)\n        \"([^@/?=&]+)\" + // Host address(es) (Group 4)\n        \"(?:/([^:@,/?=&]+)?)?\" + // Endpoint (Group 5)\n        \"(?:\\\\?([^:@,/?]+)?)?\" + // Options (Group 6)\n        \"\\\\s*$\", // Optional whitespace padding at the end of the line\n      \"gi\"\n    );\n    const connectionStringObject = {};\n\n    if (!uri.includes(\"://\")) {\n      throw new Error(`No scheme found in URI ${uri}`);\n    }\n\n    const tokens = connectionStringParser.exec(uri);\n\n    if (Array.isArray(tokens)) {\n      connectionStringObject.scheme = tokens[1];\n      if (this.scheme && this.scheme !== connectionStringObject.scheme) {\n        throw new Error(`URI must start with '${this.scheme}://'`);\n      }\n      connectionStringObject.username = tokens[2]\n        ? decodeURIComponent(tokens[2])\n        : tokens[2];\n      connectionStringObject.password = tokens[3]\n        ? decodeURIComponent(tokens[3])\n        : tokens[3];\n      connectionStringObject.hosts = this._parseAddress(tokens[4]);\n      connectionStringObject.endpoint = tokens[5]\n        ? decodeURIComponent(tokens[5])","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js#L84-L120","documentation":"Thrown by ConnectionStringParser.parse when the URI contains no '://' separator, i.e. there is no scheme to extract before the regex is applied. The parser requires an explicit scheme even for localhost-only strings, because the scheme is both a validation anchor and compared against the parser's fixed scheme when one is set.","triggerScenarios":"Parsing 'localhost:3306/mydb', 'user:pass@dbhost:5432/x', or a bare host with credentials but no scheme; config templates that document scheme-less DSNs; env vars that were truncated when copied.","commonSituations":"Users paste DSNs from older clients that omit the protocol; DATABASE_URL-style variables stored without scheme after a migration; trailing whitespace is fine (regex tolerates it) but a missing protocol is fatal.","solutions":["Prefix the correct scheme for the connector: 'mysql://localhost:3306/mydb', 'postgresql://...', 'sqlserver://...'.","If the scheme is unknown at runtime, default it before parsing: uri = uri.includes('://') ? uri : `postgresql://${uri}`.","Log the offending URI (with credentials masked) at the config-loading layer to catch truncation early."],"exampleFix":"// before\nparser.parse(\"localhost:5432/appdb\")  // throws: No scheme found in URI\n\n// after\nparser.parse(\"postgresql://localhost:5432/appdb\")","handlingStrategy":"validation","validationCode":"function ensureScheme(uri, defaultScheme = \"postgresql\") {\n  if (typeof uri !== \"string\" || uri.trim().length === 0) {\n    throw new Error(\"connection string is empty\");\n  }\n  return uri.includes(\"://\") ? uri : `${defaultScheme}://${uri}`;\n}\nconst safeUri = ensureScheme(process.env.DATABASE_URL, \"postgresql\");","typeGuard":"/** @param {unknown} uri @returns {boolean} */\nfunction hasScheme(uri) {\n  return typeof uri === \"string\" && uri.includes(\"://\");\n}","tryCatchPattern":"try {\n  const parsed = parser.parse(uri);\n} catch (e) {\n  if (e.message.startsWith(\"No scheme found in URI\")) {\n    parsed = parser.parse(`${expectedScheme}://${uri}`); // prepend once, then retry\n  } else throw e;\n}","preventionTips":["Require scheme-ful URIs in config validation with a clear error naming the expected scheme.","Never store bare host:port DSNs; migrate them to scheme-ful form.","Copy env values fully — truncation at ':' is a classic paste failure."],"tags":["sql-agent","connection-string","uri-parsing","config"],"backgroundTag":"malformed-connection-string","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}