{"record":{"id":"608747caa776d327","repo":"mastra-ai/mastra","slug":"configdirname-must-be-a-non-empty-directory-name","errorCode":null,"errorMessage":"configDirName must be a non-empty directory name","messagePattern":"configDirName must be a non-empty directory name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/constants.ts","lineNumber":12,"sourceCode":"import * as path from 'node:path';\n\n// Default config directory name used for all project-level and global config paths.\nexport const DEFAULT_CONFIG_DIR = '.mastracode';\n\n/**\n * Validate that a configDirName is a safe single directory name.\n * Rejects absolute paths, path separators, and traversal components.\n */\nexport function validateConfigDirName(configDirName: string): void {\n  if (configDirName.trim().length === 0) {\n    throw new Error('configDirName must be a non-empty directory name');\n  }\n\n  if (\n    path.isAbsolute(configDirName) ||\n    configDirName.includes('/') ||\n    configDirName.includes('\\\\') ||\n    configDirName === '..' ||\n    configDirName === '.'\n  ) {\n    throw new Error(\n      `configDirName must be a single directory name without path separators or traversal components, got: \"${configDirName}\"`,\n    );\n  }\n}\n\n// Default OM model - using gemini-3.5-flash for efficiency\nexport const DEFAULT_OM_MODEL_ID = process.env.DEFAULT_OM_MODEL_ID ?? 'google/gemini-3.5-flash';\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/constants.ts#L1-L30","documentation":"validateConfigDirName() rejects configDirName values whose trimmed content is empty (whitespace-only strings included). The library stores per-project state under a single directory name, so it must have actual content before being joined into a path. It throws eagerly at controller creation time via createMastraCodeAgentController.","triggerScenarios":"Calling createMastraCodeAgentController({ configDirName: '' }) or with a whitespace-only value like '   ' (or an undefined-derived empty string from env/CLI parsing) — validateConfigDirName's first check (trim().length === 0) fires.","commonSituations":"Reading configDirName from an unset environment variable, an empty CLI flag value (--config-dir=), a JSON config field left as \"\", or defaulting with '' instead of a real name.","solutions":["Pass a non-empty single directory name, e.g. createMastraCodeAgentController({ configDirName: '.mastra-code' }).","If sourcing from env/CLI, coalesce to a default: configDirName ?? '.mastra-code', and trim before passing.","Guard with a trim check before calling the SDK so the failure surfaces at your config boundary."],"exampleFix":"// before\ncreateMastraCodeAgentController({ configDirName: process.env.MASTRA_CONFIG_DIR ?? '' });\n// after\nconst configDirName = process.env.MASTRA_CONFIG_DIR?.trim() || '.mastra-code';\ncreateMastraCodeAgentController({ configDirName });","handlingStrategy":"validation","validationCode":"function isValidConfigDirName(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}\nif (!isValidConfigDirName(configDirName)) {\n  throw new Error('configDirName must be a non-empty directory name');\n}","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  controller = await createMastraCodeAgentController({ configDirName });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('configDirName must be a non-empty directory name')) {\n    controller = await createMastraCodeAgentController({ configDirName: '.mastra-code' });\n  } else { throw err; }\n}","preventionTips":["Never default configDirName to ''; always coalesce to a named default like '.mastra-code'.","Trim env/CLI-sourced values before passing them in.","Validate config objects at your boundary before handing them to the SDK."],"tags":["configuration","validation","argument-error"],"backgroundTag":"invalid-config-dir-name","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}