{"record":{"id":"0449e620a3390147","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"invalid-module-name-mod-module-must-match","errorCode":null,"errorMessage":"Invalid module name '${mod.module}': must match ${MODULE_RE}","messagePattern":"Invalid module name '(.+?)': must match (.+?)","errorType":"validation","errorClass":"ParamRegistryError","httpStatus":null,"severity":"error","filePath":"MemoryCore/src/metadata/config/param-registry.ts","lineNumber":87,"sourceCode":"}\n\n/**\n * 从已解析的对象构建注册表（可用于测试）。\n */\nexport function buildRegistry(data: ConfigParamsFile): ConfigParamRegistry {\n  if (!data.version || !Array.isArray(data.modules)) {\n    throw new ParamRegistryError(\"Config params file must have 'version' and 'modules' array\");\n  }\n\n  const registry: ConfigParamRegistry = new Map();\n  const seenModules = new Set<string>();\n\n  for (const mod of data.modules) {\n    if (!mod.module || typeof mod.module !== \"string\") {\n      throw new ParamRegistryError(\"Each module entry must have a 'module' string field\");\n    }\n    if (!MODULE_RE.test(mod.module)) {\n      throw new ParamRegistryError(\n        `Invalid module name '${mod.module}': must match ${MODULE_RE}`,\n      );\n    }\n    if (seenModules.has(mod.module)) {\n      throw new ParamRegistryError(`Duplicate module '${mod.module}'`);\n    }\n    seenModules.add(mod.module);\n\n    if (!mod.description) {\n      throw new ParamRegistryError(`Module '${mod.module}' must have a description`);\n    }\n    if (!Array.isArray(mod.params) || mod.params.length === 0) {\n      throw new ParamRegistryError(`Module '${mod.module}' must have at least one param`);\n    }\n\n    const seenParams = new Set<string>();\n    for (const param of mod.params) {\n      if (!param.param_name || typeof param.param_name !== \"string\") {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/metadata/config/param-registry.ts#L69-L105","documentation":"This error is thrown by buildRegistry when validating a module entry in the parameter registry file whose 'module' name does not match MODULE_RE. The library enforces a strict naming convention so module identifiers are consistent and safe to use as keys/paths. It is a ParamRegistryError raised during loadParamRegistry, so loading the registry fails until the name is corrected.","triggerScenarios":"loadParamRegistry parses a registry JSON where data.modules[i].module is set but fails the MODULE_RE regular expression test (e.g. contains spaces, uppercase, hyphens, or illegal characters allowed by the pattern).","commonSituations":"Hand-edited registry files with a module name like 'My Module' or 'my-module' when the pattern expects snake_case; renamed modules after a version change; copy-pasted names with trailing whitespace.","solutions":["Check the MODULE_RE definition at the top of param-registry.ts to see the exact allowed format","Rename the module in the registry file to match the pattern (usually lowercase snake_case)","Strip whitespace and illegal characters from the module name","Add a schema/pattern check to your editor or CI that validates module names against MODULE_RE before the registry is loaded"],"exampleFix":"// before\n{ \"module\": \"My-Module\", \"description\": \"...\", \"params\": [ ... ] }\n// after\n{ \"module\": \"my_module\", \"description\": \"...\", \"params\": [ ... ] }","handlingStrategy":"validation","validationCode":"const MODULE_RE = /^[a-z][a-z0-9_]*$/; // match the library's definition\nfunction isValidModuleName(name) {\n  return typeof name === 'string' && MODULE_RE.test(name);\n}\nif (!data.modules.every(m => isValidModuleName(m.module))) {\n  throw new Error('registry contains invalid module names');\n}","typeGuard":"function isValidModuleName(name) {\n  return typeof name === 'string' && /^[a-z][a-z0-9_]*$/.test(name);\n}","tryCatchPattern":"try {\n  const registry = await loadParamRegistry();\n} catch (e) {\n  if (e instanceof ParamRegistryError && e.message.includes('Invalid module name')) {\n    const bad = e.message.match(/'([^']+)'/)?.[1];\n    console.error(`Fix module name '${bad}' to match the required pattern`);\n  } else throw e;\n}","preventionTips":["Keep MODULE_RE's definition handy and test names against it before writing registry entries","Use lowercase snake_case for all module identifiers","Trim whitespace from names before saving the registry file","Add a CI schema check validating module names against the pattern"],"tags":["configuration","validation","registry"],"backgroundTag":"schema-validation-failed","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}