{"record":{"id":"75496f0ed49a86b3","repo":"ruvnet/ruflo","slug":"schema-name-must-not-be-empty","errorCode":null,"errorMessage":"Schema name must not be empty","messagePattern":"Schema name must not be empty","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/commands/ruvector/pg-utils.ts","lineNumber":22,"sourceCode":" *\n * @module v3/cli/commands/ruvector/pg-utils\n */\n\n/**\n * Valid PostgreSQL identifier pattern.\n * Allows only ASCII letters, digits, and underscores.\n * Must start with a letter or underscore.\n */\nconst VALID_PG_IDENTIFIER = /^[a-zA-Z_][a-zA-Z0-9_]*$/;\n\n/**\n * Validate a PostgreSQL schema name.\n * Throws if the name contains characters that could enable SQL injection.\n * Safe names are returned as-is (no quoting needed since they match the identifier pattern).\n */\nexport function validateSchemaName(schema: string): string {\n  if (!schema || schema.length === 0) {\n    throw new Error('Schema name must not be empty');\n  }\n  if (schema.length > 63) {\n    throw new Error(`Schema name too long (${schema.length} chars, max 63): \"${schema}\"`);\n  }\n  if (!VALID_PG_IDENTIFIER.test(schema)) {\n    throw new Error(\n      `Invalid schema name: \"${schema}\". Must contain only letters, digits, and underscores, and start with a letter or underscore.`\n    );\n  }\n  return schema;\n}\n\n/**\n * Validate a PostgreSQL timestamp string.\n * Only allows ISO 8601 format to prevent SQL injection via timestamp fields.\n */\nconst VALID_TIMESTAMP = /^\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:?\\d{2})?$/;\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/commands/ruvector/pg-utils.ts#L4-L40","documentation":"Thrown by validateSchemaName() when the schema string is null, undefined, or zero-length. Empty schema names are rejected because interpolating one into SQL would produce malformed statements (`CREATE SCHEMA `) or, worse, fall through to a default schema, masking a configuration bug.","triggerScenarios":"Calling a ruvector pg helper with an empty schema string, a config value that resolved to '' (e.g. env var unset, defaulted to empty), or undefined passed where a schema name was expected.","commonSituations":"Environment variable for the schema name unset (so it coerces to ''), a config loader returning '' for a missing key instead of undefined, or a migration step that forgot to set the schema.","solutions":["Provide a concrete schema name (e.g. 'public', 'ruvector', or your tenant schema).","Check the source: if it comes from env, ensure the env var is set and non-empty.","Default explicitly and loudly at the config layer rather than passing '' through."],"exampleFix":"// before\nvalidateSchemaName(process.env.PG_SCHEMA ?? '')\n// after\nconst schema = process.env.PG_SCHEMA;\nif (!schema) throw new Error('PG_SCHEMA must be set');\nvalidateSchemaName(schema);","handlingStrategy":"validation","validationCode":"function requireSchemaName(v: string | undefined | null): string {\n  if (!v || v.length === 0) throw new Error('Schema name must not be empty');\n  return v;\n}","typeGuard":"const isNonEmptySchemaName = (v: unknown): v is string =>\n  typeof v === 'string' && v.length > 0;","tryCatchPattern":"try {\n  validateSchemaName(schema);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg === 'Schema name must not be empty') {\n    schema = 'public'; // or fail loudly per your policy\n  } else throw e;\n}","preventionTips":["Treat an unset schema env var as a fatal config error.","Default explicitly at the config layer; do not pass '' through.","Fail at startup, not at the first SQL call."],"tags":["validation","postgres","security","pg-utils"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}