{"record":{"id":"3c6f74263ca662b8","repo":"mastra-ai/mastra","slug":"dataset-not-found-3c6f74","errorCode":"DATASET_NOT_FOUND","errorMessage":"Dataset not found","messagePattern":"Dataset not found","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/manager.ts","lineNumber":166,"sourceCode":"    const createScope = scopeFromArgs(input);\n    return new Dataset(result.id, this.#mastra, createScope);\n  }\n\n  /**\n   * Get an existing dataset by ID, optionally scoped to a tenant.\n   *\n   * When `organizationId` / `projectId` are provided, the read is scoped to\n   * that tenancy: a dataset row that exists but belongs to a different tenant\n   * returns NOT_FOUND (same 404 as a truly missing row) rather than leaking\n   * cross-tenant existence. The returned {@link Dataset} handle carries the\n   * scope forward on all subsequent reads and item mutations.\n   */\n  async get(args: { id: string; organizationId?: string; projectId?: string }): Promise<Dataset> {\n    const store = await this.#getDatasetsStore();\n    const scope = scopeFromArgs(args);\n    const record = await store.getDatasetById({ id: args.id, filters: scope });\n    if (!record) {\n      throw new MastraError({\n        id: 'DATASET_NOT_FOUND',\n        text: 'Dataset not found',\n        domain: 'STORAGE',\n        category: 'USER',\n      });\n    }\n    return new Dataset(args.id, this.#mastra, scope);\n  }\n\n  /**\n   * List all datasets with pagination.\n   *\n   * Supports optional tenancy and candidate-identity filters. When omitted, all\n   * datasets visible to the configured storage instance are returned.\n   */\n  async list(args?: {\n    page?: number;\n    perPage?: number;","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/manager.ts#L148-L184","documentation":"manager.get looks up a dataset by id (scoped by optional organizationId/projectId filters) via store.getDatasetById and throws DATASET_NOT_FOUND when no record matches. Raised in get and its callers (finalizeExperiment, resultA, resultB) when the referenced dataset doesn't exist or isn't visible in the given scope.","triggerScenarios":"Fetching a dataset with a wrong/deleted id; id from another project/organization passed without matching scope filters; dataset removed between creating an experiment and finalizing it.","commonSituations":"Hardcoded dataset ids drifting across environments; multi-tenant apps where projectId scoping hides the dataset; race with dataset deletion; using an experiment's datasetId after the dataset was purged.","solutions":["Verify the dataset id exists (list datasets) and matches the organizationId/projectId you pass.","Catch DATASET_NOT_FOUND and surface a user-facing 'dataset missing' message or trigger re-creation.","Check scope: pass the same organizationId/projectId used at creation time.","For finalize/result flows, guard dataset lifetime so datasets aren't deleted while experiments reference them."],"exampleFix":"// before\nconst ds = await datasets.get({ id: datasetId, organizationId, projectId }); // throws if absent\n// after\nlet ds;\ntry {\n  ds = await datasets.get({ id: datasetId, organizationId, projectId });\n} catch (err) {\n  if (err?.id === 'DATASET_NOT_FOUND') {\n    ds = await datasets.create({ name: 'evals', organizationId, projectId });\n  } else throw err;\n}","handlingStrategy":"try-catch","validationCode":"const existing = await datasets.list({ organizationId, projectId, /* name filter if available */ });\nif (!existing.some(d => d.id === datasetId)) throw new Error(`Dataset ${datasetId} not found in scope`);","typeGuard":"function isDatasetNotFound(e: unknown): e is { id: 'DATASET_NOT_FOUND'; text: string } {\n  return typeof e === 'object' && e !== null && (e as any).id === 'DATASET_NOT_FOUND';\n}","tryCatchPattern":"try {\n  return await datasets.get({ id, organizationId, projectId });\n} catch (err) {\n  if (isDatasetNotFound(err)) return null; // or re-create / report to user\n  throw err;\n}","preventionTips":["Pass the same organizationId/projectId scope used when the dataset was created.","Look up dataset ids dynamically (by name) instead of hardcoding across environments.","Prevent deleting datasets that active experiments reference (check finalizeExperiment flows).","Handle DATASET_NOT_FOUND as a first-class state in multi-tenant UIs."],"tags":["not-found","datasets","multi-tenancy"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}