{"record":{"id":"c8937f74a0528b61","repo":"mastra-ai/mastra","slug":"error-message-mastraerror-rethrown-with-mapped-st-c8937f","errorCode":null,"errorMessage":"error.message (MastraError rethrown with mapped status in BATCH_DELETE_ITEMS route)","messagePattern":"error\\.message \\(MastraError rethrown with mapped status in BATCH_DELETE_ITEMS route\\)","errorType":"http","errorClass":"HTTPException","httpStatus":null,"severity":"error","filePath":"packages/server/src/server/handlers/datasets.ts","lineNumber":1258,"sourceCode":"  path: '/datasets/:datasetId/items/batch',\n  responseType: 'json',\n  pathParamSchema: datasetIdPathParams,\n  bodySchema: batchDeleteItemsBodySchema,\n  responseSchema: batchDeleteItemsResponseSchema,\n  summary: 'Batch delete items from dataset',\n  description: 'Deletes multiple items from the dataset in a single operation (single version entry)',\n  tags: ['Datasets'],\n  requiresAuth: true,\n  handler: async ({ mastra, datasetId, ...params }) => {\n    assertDatasetsAvailable();\n    try {\n      const { itemIds } = params as { itemIds: string[] };\n      const ds = await mastra.datasets.get({ id: datasetId });\n      await ds.deleteItems({ itemIds });\n      return { success: true, deletedCount: itemIds.length };\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 bulk deleting items');\n    }\n  },\n});\n\n// ============================================================================\n// AI Generation\n// ============================================================================\n\nconst GENERATE_ITEMS_SYSTEM_PROMPT = `You are a test data generation expert. Your job is to generate realistic, diverse test data items for an AI agent evaluation dataset.\n\nYou will be given context about the agent being tested — its purpose, system prompt, and available tools. Use this to generate inputs that thoroughly exercise the agent's capabilities.\n\nGenerate test items that:\n1. Are realistic and diverse — cover edge cases, different complexities, and various scenarios\n2. Match the provided schemas exactly\n3. Include ground truth values when a ground truth schema is provided","sourceCodeStart":1240,"sourceCodeEnd":1276,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/datasets.ts#L1240-L1276","documentation":"Fallback branch of the BATCH_DELETE_ITEMS route (DELETE /datasets/:datasetId/items/batch): if ds.deleteItems throws a MastraError, the handler rethrows it as an HTTPException whose status is mapped from the error ID via getHttpStatusForMastraError and whose body carries the original error.message.","triggerScenarios":"DELETE /datasets/:datasetId/items/batch where mastra.datasets.get or ds.deleteItems throws a MastraError — nonexistent dataset, storage failure, or a delete constraint error raised by the storage adapter.","commonSituations":"Deleting items from a dataset ID that doesn't exist (typo or stale cache); storage backend outage; itemIds already deleted by a concurrent request if storage surfaces that as a MastraError; datasets feature not configured in the deployment.","solutions":["Check the response status and error.message to identify the mapped MastraError.","Verify the datasetId exists via GET /api/datasets.","Confirm the itemIds list is non-empty and well-formed (array of strings) per batchDeleteItemsBodySchema.","Check storage backend health; retry transient failures with backoff."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!Array.isArray(itemIds) || itemIds.length === 0 || itemIds.some(id => typeof id !== 'string' || !id)) {\n  throw new Error('itemIds must be a non-empty array of non-empty strings');\n}\nconst datasets = await fetch('/api/datasets').then(r => r.json());\nif (!datasets.datasets?.some(d => d.id === datasetId)) {\n  throw new Error(`Dataset ${datasetId} not found before batch delete`);\n}","typeGuard":"function isValidItemIds(v: unknown): v is string[] {\n  return Array.isArray(v) && v.length > 0 && v.every(id => typeof id === 'string' && id.length > 0);\n}","tryCatchPattern":"try {\n  const res = await fetch(`/api/datasets/${datasetId}/items/batch`, {\n    method: 'DELETE',\n    body: JSON.stringify({ itemIds }),\n  });\n  if (!res.ok) {\n    const body = await res.json().catch(() => null);\n    throw new Error(`batch delete failed (${res.status}): ${body?.message ?? res.statusText}`);\n  }\n  return await res.json();\n} catch (err) {\n  if (isTransientStorageError(err)) {\n    await sleep(backoff);\n    return batchDeleteItems(datasetId, itemIds); // deletes are idempotent\n  }\n  throw err;\n}","preventionTips":["Validate the itemIds array shape client-side before the DELETE call.","Confirm the datasetId exists before deleting.","Treat deletes as idempotent so retries after transient storage errors are safe.","Monitor storage backend health to distinguish code bugs from infra failures."],"tags":["mastra-error","http-mapping","storage","batch-delete","datasets"],"backgroundTag":"storage-backend-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}