mastra-ai/mastra · error · Error

Dataset not found: ${args.id}

Error message

Dataset not found: ${args.id}

What it means

updateDataset() first fetches the dataset via getDatasetById; if no dataset exists for args.id (under the given filters), it throws a plain Error "Dataset not found: <id>" instead of attempting an update. It is a standard missing-resource guard.

Source

Thrown at packages/core/src/storage/domains/datasets/base.ts:107

   * if it also matches the tenancy filters — returns `null` on mismatch (never
   * throws, to avoid leaking existence across tenants via error timing/text).
   */
  abstract getDatasetById(args: { id: string; filters?: DatasetTenancyFilters }): Promise<DatasetRecord | null>;
  /**
   * Delete a dataset. When `filters` is provided, the delete is a silent no-op
   * if the row does not match the tenancy filters. Never throws on mismatch.
   */
  abstract deleteDataset(args: { id: string; filters?: DatasetTenancyFilters }): Promise<void>;
  abstract listDatasets(args: ListDatasetsInput): Promise<ListDatasetsOutput>;

  /**
   * Update a dataset. Validates existing items against new schemas if schemas are changing.
   * Subclasses implement _doUpdateDataset for actual storage operation.
   */
  async updateDataset(args: UpdateDatasetInput): Promise<DatasetRecord> {
    const existing = await this.getDatasetById({ id: args.id, filters: args.filters });
    if (!existing) {
      throw new Error(`Dataset not found: ${args.id}`);
    }

    // Check if schemas are being added or modified
    const inputSchemaChanging =
      args.inputSchema !== undefined && JSON.stringify(args.inputSchema) !== JSON.stringify(existing.inputSchema);
    const groundTruthSchemaChanging =
      args.groundTruthSchema !== undefined &&
      JSON.stringify(args.groundTruthSchema) !== JSON.stringify(existing.groundTruthSchema);

    // If schemas changing, validate all existing items against new schemas
    if (inputSchemaChanging || groundTruthSchemaChanging) {
      const itemsResult = await this.listItems({
        datasetId: args.id,
        pagination: { page: 0, perPage: false }, // Get all items
      });
      const items = itemsResult.items;

      if (items.length > 0) {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the id via getDatasetById/listDatasets before updating
  2. Check the filters passed in updateDataset aren't excluding the dataset
  3. Confirm you're connected to the same storage backend/environment where the dataset was created
  4. Recreate the dataset if it was deleted

Example fix

// before
await storage.updateDataset({ id: 'ds_typo', inputSchema })
// after
const ds = await storage.getDatasetById({ id: 'ds_typo' });
if (ds) await storage.updateDataset({ id: 'ds_typo', inputSchema });
Defensive patterns

Strategy: validation

Validate before calling

const ds = await storage.getDatasetById({ id: args.id, filters: args.filters });
if (!ds) throw new Error(`dataset ${args.id} not found`);

Type guard

null

Try / catch

try {
  await storage.updateDataset(args);
} catch (e) {
  if (e.message.startsWith('Dataset not found:')) { /* recreate or correct id/filters */ }
  throw e;
}

Prevention

When it happens

Trigger: Calling storage.updateDataset({ id }) where the id doesn't exist, was already deleted, or is filtered out by args.filters (different workspace/scope filters hiding the record).

Common situations: Typo in dataset id, environment mismatch (dataset created in another DB/env), filters inadvertently excluding the record, race with a concurrent delete, storage adapter not pointed at the right database.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/fdce452fc92d86a7. Report an issue: GitHub.