{"record":{"id":"696202858105d549","repo":"mastra-ai/mastra","slug":"error-message-mastraerror-rethrown-with-mapped-st-696202","errorCode":null,"errorMessage":"error.message (MastraError rethrown with mapped status in LIST_ITEM_VERSIONS route)","messagePattern":"error\\.message \\(MastraError rethrown with mapped status in LIST_ITEM_VERSIONS route\\)","errorType":"http","errorClass":"HTTPException","httpStatus":null,"severity":"error","filePath":"packages/server/src/server/handlers/datasets.ts","lineNumber":1140,"sourceCode":"  pathParamSchema: datasetAndItemIdPathParams,\n  responseSchema: listItemVersionsResponseSchema,\n  summary: 'Get item history',\n  description: 'Returns the full SCD-2 history of the item across all dataset versions',\n  tags: ['Datasets'],\n  requiresAuth: true,\n  handler: async ({ mastra, datasetId, itemId }) => {\n    assertDatasetsAvailable();\n    try {\n      const ds = await mastra.datasets.get({ id: datasetId });\n      const rows = await ds.getItemHistory({ itemId });\n      // Check rows belong to this dataset\n      if (rows.length > 0 && rows[0]?.datasetId !== datasetId) {\n        throw new HTTPException(404, { message: `Item not found in dataset: ${itemId}` });\n      }\n      return { history: rows };\n    } catch (error) {\n      if (error instanceof MastraError) {\n        throw new HTTPException(getHttpStatusForMastraError(error.id) as StatusCode, { message: error.message });\n      }\n      return handleError(error, 'Error listing item history');\n    }\n  },\n});\n\nexport const GET_ITEM_VERSION_ROUTE = createRoute({\n  method: 'GET',\n  path: '/datasets/:datasetId/items/:itemId/versions/:datasetVersion',\n  responseType: 'json',\n  pathParamSchema: datasetItemVersionPathParams,\n  responseSchema: datasetItemResponseSchema.nullable(),\n  summary: 'Get item at specific dataset version',\n  description: 'Returns the item as it existed at a specific dataset version',\n  tags: ['Datasets'],\n  requiresAuth: true,\n  handler: async ({ mastra, datasetId, itemId, datasetVersion }) => {\n    assertDatasetsAvailable();","sourceCodeStart":1122,"sourceCodeEnd":1158,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/datasets.ts#L1122-L1158","documentation":"Fallback branch of the LIST_ITEM_VERSIONS route: when ds.getItemHistory (or mastra.datasets.get) throws a MastraError, the handler rethrows it as an HTTPException whose status code is derived from the Mastra error ID via getHttpStatusForMastraError, and whose message is the original error.message. The message you see is the underlying storage/dataset error surfaced over HTTP.","triggerScenarios":"GET /datasets/:datasetId/items/:itemId/history fails inside ds.getItemHistory or mastra.datasets.get with a MastraError (e.g. dataset not found, storage backend error, datasets feature unavailable).","commonSituations":"Dataset ID doesn't exist so storage throws; storage backend (LibSQL/PG/Upstash) unreachable or misconfigured; calling a deployments where the datasets feature/storage domain is not registered; serialization of storage failures into MastraError with mapped status codes.","solutions":["Read error.message in the response — it names the underlying MastraError (and its ID region) to fix the root cause.","Verify the datasetId exists: GET /api/datasets and confirm the ID.","Check the storage backend configuration/connection (DATABASE_URL etc.) and that the storage adapter is healthy.","Confirm the Mastra instance registers dataset storage (assertDatasetsAvailable passes) in the deployment being called."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const datasets = await fetch('/api/datasets').then(r => r.json());\nif (!datasets.datasets?.some(d => d.id === datasetId)) {\n  throw new Error(`Dataset ${datasetId} does not exist on this server`);\n}","typeGuard":"function isMastraErrorPayload(body: unknown): body is { message: string } {\n  return typeof body === 'object' && body !== null && 'message' in body && typeof (body as any).message === 'string';\n}","tryCatchPattern":"try {\n  const res = await fetch(`/api/datasets/${datasetId}/items/${itemId}/history`);\n  if (!res.ok) {\n    const body = await res.json().catch(() => null);\n    throw new Error(`history fetch failed (${res.status}): ${body?.message ?? res.statusText}`);\n  }\n  return await res.json();\n} catch (err) {\n  // storage/dataset MastraError: surface message, optionally retry transient storage failures\n  console.error(err);\n  throw err;\n}","preventionTips":["Verify storage backend env vars (DATABASE_URL etc.) before starting the server.","Confirm the datasets/storage domain is registered in your Mastra deployment.","Validate dataset IDs against GET /api/datasets before calling item endpoints.","Add health checks for the storage adapter in deployment pipelines."],"tags":["mastra-error","http-mapping","storage","datasets"],"backgroundTag":"storage-backend-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}