mastra-ai/mastra · error · MastraError
DATASET_INVALID_ID
DATASET_INVALID_ID
Error message
Caller-defined dataset ID must not be empty
What it means
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.
Source
Thrown at packages/core/src/storage/domains/datasets/base.ts:48
/**
* Abstract base class for datasets storage domain.
* Provides the contract for dataset and dataset item CRUD operations.
*
* Schema validation is handled in this base class via Template Method pattern.
* Subclasses implement protected _do* methods for actual storage operations,
* including SCD-2 versioning (version bump, row ops, dataset_version insert).
*/
export abstract class DatasetsStorage extends StorageDomain {
constructor() {
super({
component: 'STORAGE',
name: 'DATASETS',
});
}
protected validateCallerDefinedDatasetId(id: string): void {
if (id.length === 0) {
throw new MastraError({
id: 'DATASET_INVALID_ID',
domain: ErrorDomain.STORAGE,
category: ErrorCategory.USER,
details: { id },
text: 'Caller-defined dataset ID must not be empty',
});
}
}
/**
* Returns an existing dataset when a caller-defined ID is reused compatibly.
* Optional immutable fields normalize omitted and null values to the same value.
*/
protected resolveExistingDataset(existing: DatasetRecord, input: CreateDatasetInput & { id: string }): DatasetRecord {
const hasConflict = DATASET_IMMUTABLE_FIELDS.some(field => (existing[field] ?? null) !== (input[field] ?? null));
if (hasConflict) {
throw new MastraError({View on GitHub (pinned to 75dd419e61)
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
Example fix
// before
await storage.createDataset({ id: process.env.DATASET_ID ?? '', name: 'x' })
// after
const id = process.env.DATASET_ID || crypto.randomUUID();
if (!id) throw new Error('Dataset id required');
await storage.createDataset({ id, name: 'x' }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof id !== 'string' || id.length === 0) throw new Error('dataset id required'); Type guard
function isValidDatasetId(id: unknown): id is string {
return typeof id === 'string' && id.length > 0;
} Try / catch
try {
await storage.createDataset({ id, name });
} catch (e) {
if (e instanceof MastraError && e.id === 'DATASET_INVALID_ID') { /* fix input */ }
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Building the id from env vars/config that resolved to empty string, UI inputs not validated client-side, code paths like `id: someVar ?? ''`.
Related errors
- DATASET_ITEM_EXTERNAL_ID_INVALID
- COMPARE_INVALID_INPUT
- Dataset not found: ${args.id}
- SchemaUpdateValidationError
- [FilesystemStorage] resourceId must not be empty.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/54e5e9f2bf1783b0.
Report an issue: GitHub.