Mintplex-Labs/anything-llm · error

No scheme found in URI ${uri}

Error message

No scheme found in URI ${uri}

What it means

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.

Source

Thrown at server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js:102

   * present in the input.
   * @param {string} uri The connection string URI
   * @returns {ConnectionStringObject} The connection string object
   */
  parse(uri) {
    const connectionStringParser = new RegExp(
      "^\\s*" + // Optional whitespace padding at the beginning of the line
        "([^:]+)://" + // Scheme (Group 1)
        "(?:([^:@,/?=&]+)(?::([^:@,/?=&]+))?@)?" + // User (Group 2) and Password (Group 3)
        "([^@/?=&]+)" + // Host address(es) (Group 4)
        "(?:/([^:@,/?=&]+)?)?" + // Endpoint (Group 5)
        "(?:\\?([^:@,/?]+)?)?" + // Options (Group 6)
        "\\s*$", // Optional whitespace padding at the end of the line
      "gi"
    );
    const connectionStringObject = {};

    if (!uri.includes("://")) {
      throw new Error(`No scheme found in URI ${uri}`);
    }

    const tokens = connectionStringParser.exec(uri);

    if (Array.isArray(tokens)) {
      connectionStringObject.scheme = tokens[1];
      if (this.scheme && this.scheme !== connectionStringObject.scheme) {
        throw new Error(`URI must start with '${this.scheme}://'`);
      }
      connectionStringObject.username = tokens[2]
        ? decodeURIComponent(tokens[2])
        : tokens[2];
      connectionStringObject.password = tokens[3]
        ? decodeURIComponent(tokens[3])
        : tokens[3];
      connectionStringObject.hosts = this._parseAddress(tokens[4]);
      connectionStringObject.endpoint = tokens[5]
        ? decodeURIComponent(tokens[5])

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Prefix the correct scheme for the connector: 'mysql://localhost:3306/mydb', 'postgresql://...', 'sqlserver://...'.
  2. If the scheme is unknown at runtime, default it before parsing: uri = uri.includes('://') ? uri : `postgresql://${uri}`.
  3. Log the offending URI (with credentials masked) at the config-loading layer to catch truncation early.

Example fix

// before
parser.parse("localhost:5432/appdb")  // throws: No scheme found in URI

// after
parser.parse("postgresql://localhost:5432/appdb")
Defensive patterns

Strategy: validation

Validate before calling

function ensureScheme(uri, defaultScheme = "postgresql") {
  if (typeof uri !== "string" || uri.trim().length === 0) {
    throw new Error("connection string is empty");
  }
  return uri.includes("://") ? uri : `${defaultScheme}://${uri}`;
}
const safeUri = ensureScheme(process.env.DATABASE_URL, "postgresql");

Type guard

/** @param {unknown} uri @returns {boolean} */
function hasScheme(uri) {
  return typeof uri === "string" && uri.includes("://");
}

Try / catch

try {
  const parsed = parser.parse(uri);
} catch (e) {
  if (e.message.startsWith("No scheme found in URI")) {
    parsed = parser.parse(`${expectedScheme}://${uri}`); // prepend once, then retry
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/258f647081c81994. Report an issue: GitHub.