{"record":{"id":"54e5e9f2bf1783b0","repo":"mastra-ai/mastra","slug":"dataset-invalid-id","errorCode":"DATASET_INVALID_ID","errorMessage":"Caller-defined dataset ID must not be empty","messagePattern":"Caller-defined dataset ID must not be empty","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/datasets/base.ts","lineNumber":48,"sourceCode":"/**\n * Abstract base class for datasets storage domain.\n * Provides the contract for dataset and dataset item CRUD operations.\n *\n * Schema validation is handled in this base class via Template Method pattern.\n * Subclasses implement protected _do* methods for actual storage operations,\n * including SCD-2 versioning (version bump, row ops, dataset_version insert).\n */\nexport abstract class DatasetsStorage extends StorageDomain {\n  constructor() {\n    super({\n      component: 'STORAGE',\n      name: 'DATASETS',\n    });\n  }\n\n  protected validateCallerDefinedDatasetId(id: string): void {\n    if (id.length === 0) {\n      throw new MastraError({\n        id: 'DATASET_INVALID_ID',\n        domain: ErrorDomain.STORAGE,\n        category: ErrorCategory.USER,\n        details: { id },\n        text: 'Caller-defined dataset ID must not be empty',\n      });\n    }\n  }\n\n  /**\n   * Returns an existing dataset when a caller-defined ID is reused compatibly.\n   * Optional immutable fields normalize omitted and null values to the same value.\n   */\n  protected resolveExistingDataset(existing: DatasetRecord, input: CreateDatasetInput & { id: string }): DatasetRecord {\n    const hasConflict = DATASET_IMMUTABLE_FIELDS.some(field => (existing[field] ?? null) !== (input[field] ?? null));\n\n    if (hasConflict) {\n      throw new MastraError({","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/datasets/base.ts#L30-L66","documentation":"Base dataset storage validates caller-supplied dataset IDs in validateCallerDefinedDatasetId(); an empty string id is rejected with a MastraError (DATASET_INVALID_ID, USER category) before any storage operation runs. Dataset ids are caller-defined keys and must be non-empty.","triggerScenarios":"Calling createDataset (or another path invoking this validator) with id: '' — typically from an unset variable, an empty form field, or a template that failed to interpolate.","commonSituations":"Building the id from env vars/config that resolved to empty string, UI inputs not validated client-side, code paths like `id: someVar ?? ''`.","solutions":["Ensure the id is non-empty before calling createDataset","Generate an id when none exists (crypto.randomUUID() or a slug from the name)","Add input validation at your API boundary to reject empty ids early"],"exampleFix":"// before\nawait storage.createDataset({ id: process.env.DATASET_ID ?? '', name: 'x' })\n// after\nconst id = process.env.DATASET_ID || crypto.randomUUID();\nif (!id) throw new Error('Dataset id required');\nawait storage.createDataset({ id, name: 'x' });","handlingStrategy":"validation","validationCode":"if (typeof id !== 'string' || id.length === 0) throw new Error('dataset id required');","typeGuard":"function isValidDatasetId(id: unknown): id is string {\n  return typeof id === 'string' && id.length > 0;\n}","tryCatchPattern":"try {\n  await storage.createDataset({ id, name });\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'DATASET_INVALID_ID') { /* fix input */ }\n  throw e;\n}","preventionTips":["Validate ids at your API/UI boundary","Avoid `?? ''` fallbacks for identifiers","Generate ids when not user-supplied","Require non-empty id in config schema validation"],"tags":["storage","datasets","validation","user-input"],"backgroundTag":"missing-or-invalid-identifier","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}