{"record":{"id":"6c3878b1bbe5ed2a","repo":"mastra-ai/mastra","slug":"error-message-mastraerror-rethrown-with-mapped-st-6c3878","errorCode":null,"errorMessage":"error.message (MastraError rethrown with mapped status in BATCH_INSERT_ITEMS route)","messagePattern":"error\\.message \\(MastraError rethrown with mapped status in BATCH_INSERT_ITEMS route\\)","errorType":"http","errorClass":"HTTPException","httpStatus":null,"severity":"error","filePath":"packages/server/src/server/handlers/datasets.ts","lineNumber":1231,"sourceCode":"      return { items: addedItems, count: addedItems.length };\n    } catch (error) {\n      if (isSchemaValidationError(error)) {\n        throw new HTTPException(400, {\n          message: error.message,\n          cause: { field: error.field, errors: error.errors },\n        });\n      }\n      if (error instanceof MastraError) {\n        if (error.id === 'DATASET_ITEM_IDENTITY_CONFLICT') {\n          throw new HTTPException(409, {\n            message: error.message,\n            cause: { conflicts: 'conflicts' in error ? error.conflicts : [] },\n          });\n        }\n        if (error.id === 'DATASET_ITEM_EXTERNAL_ID_INVALID') {\n          throw new HTTPException(400, { message: error.message, cause: { field: 'externalId' } });\n        }\n        throw new HTTPException(getHttpStatusForMastraError(error.id) as StatusCode, { message: error.message });\n      }\n      return handleError(error, 'Error batch inserting items');\n    }\n  },\n});\n\nexport const BATCH_DELETE_ITEMS_ROUTE = createRoute({\n  method: 'DELETE',\n  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 }) => {","sourceCodeStart":1213,"sourceCodeEnd":1249,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/datasets.ts#L1213-L1249","documentation":"Catch-all branch of the BATCH_INSERT_ITEMS route: any MastraError not matched by the schema-validation, IDENTITY_CONFLICT, or EXTERNAL_ID_INVALID special cases is rethrown as an HTTPException with a status mapped from the error ID via getHttpStatusForMastraError and the original error.message in the body.","triggerScenarios":"POST /datasets/:datasetId/items/batch where ds.addItems or mastra.datasets.get throws any other MastraError — dataset not found, storage backend failure, feature unavailable, etc.","commonSituations":"Batch inserting into a nonexistent datasetId; storage adapter (LibSQL/PG) connection problems; datasets domain not registered in the deployment so assertDatasetsAvailable-adjacent storage calls fail; permission/auth failures surfaced as MastraError.","solutions":["Use the response's HTTP status and error.message to identify the mapped MastraError root cause.","Confirm the datasetId exists via GET /api/datasets.","Verify storage backend connectivity and configuration.","Retry only for transient storage errors after confirming the request payload is valid."],"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} not found before batch insert`);\n}","typeGuard":"function isHttpErrorWithMessage(body: unknown): body is { message: string } {\n  return typeof body === 'object' && body !== null && typeof (body as any).message === 'string';\n}","tryCatchPattern":"try {\n  return await batchInsertItems(datasetId, items);\n} catch (err) {\n  if (isTransient(err.status)) { // 503/502/timeout from mapped storage errors\n    await sleep(backoff);\n    return batchInsertItems(datasetId, items);\n  }\n  console.error(`batch insert failed (${err.status}): ${err.body?.message}`);\n  throw err;\n}","preventionTips":["Validate the datasetId exists before batch writes.","Validate the payload against the dataset schemas and ID rules first so only genuine infra errors remain.","Check storage backend connectivity/config in health checks.","Only retry on clearly transient statuses; treat 400/404/409 as code bugs."],"tags":["mastra-error","http-mapping","storage","batch-insert"],"backgroundTag":"storage-backend-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}