{"record":{"id":"af19244022b91314","repo":"mastra-ai/mastra","slug":"error-message-mastraerror-rethrown-with-mapped-st-af1924","errorCode":null,"errorMessage":"error.message (MastraError rethrown with mapped status in SUBMIT_EXPERIMENT_RESULT route)","messagePattern":"error\\.message \\(MastraError rethrown with mapped status in SUBMIT_EXPERIMENT_RESULT route\\)","errorType":"http","errorClass":"HTTPException","httpStatus":null,"severity":"error","filePath":"packages/server/src/server/handlers/datasets.ts","lineNumber":913,"sourceCode":"          }[];\n        };\n      const ds = await mastra.datasets.get({ id: datasetId });\n      return await ds.submitExperimentResult({\n        experimentId,\n        itemId,\n        attempt,\n        input,\n        output,\n        groundTruth,\n        error,\n        startedAt,\n        completedAt,\n        traceId,\n        scores,\n      });\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 submitting experiment result');\n    }\n  },\n});\n\nexport const FINALIZE_EXPERIMENT_ROUTE = createRoute({\n  method: 'POST',\n  path: '/datasets/:datasetId/experiments/:experimentId/finalize',\n  responseType: 'json',\n  pathParamSchema: datasetAndExperimentIdPathParams,\n  responseSchema: experimentResponseSchema,\n  summary: 'Finalize an external experiment',\n  description:\n    'Marks an external experiment completed. The server computes succeeded/failed/skipped counts from the persisted result rows. Idempotent: finalizing an already-completed experiment returns the stored record.',\n  tags: ['Datasets'],\n  requiresAuth: true,\n  handler: async ({ mastra, datasetId, experimentId }) => {","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/datasets.ts#L895-L931","documentation":"Rethrow site in the SUBMIT_EXPERIMENT_RESULT route (datasets.ts:913): a MastraError thrown while submitting results (status, completedAt, traceId, scores payload) is rethrown as HTTPException with the id-mapped HTTP status and the original error.message. Non-Mastra failures are collapsed into handleError's 'Error submitting experiment result'.","triggerScenarios":"POSTing an experiment result whose validation or persistence raises a MastraError — unknown experimentId, malformed scores, invalid completedAt, or storage write failure on the result record.","commonSituations":"Workers submitting results after the experiment was deleted or already completed; score payloads not matching the expected schema; database connectivity loss in distributed runs.","solutions":["Follow the mapped status: 4xx ids indicate validate the payload (experimentId, scores shape, completedAt format); 5xx ids indicate retry after fixing storage.","Confirm the experiment exists and is still accepting results before submitting.","Add idempotent submit logic (check existing result for experimentId/itemId) to avoid duplicate/terminal-state errors."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!experimentId) throw new Error('experimentId is required to submit results');\nif (scores && typeof scores !== 'object') throw new Error('scores must be an object');","typeGuard":"function isMastraHttpError(e: unknown): e is { status: number; message: string } {\n  return typeof e === 'object' && e !== null && 'status' in e && 'message' in e;\n}","tryCatchPattern":"try {\n  await submitExperimentResult({ experimentId, itemId, status, completedAt, traceId, scores });\n} catch (e) {\n  if (isMastraHttpError(e) && e.status >= 500) {\n    // persist result locally and retry submit later\n  }\n}","preventionTips":["Validate the result payload (experimentId, status, scores shape) before submission.","Confirm the experiment accepts results (not deleted/completed) before submitting.","Queue and retry result submissions on 5xx to survive transient storage outages."],"tags":["server","error-mapping","experiments","results"],"backgroundTag":"mastra-error-mapped-to-http-status","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}