{"record":{"id":"61aea6ed9c30eb3d","repo":"linshenkx/prompt-optimizer","slug":"function-mode-must-not-be-empty","errorCode":null,"errorMessage":"Function mode must not be empty.","messagePattern":"Function mode must not be empty\\.","errorType":"validation","errorClass":"EvaluationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":461,"sourceCode":"          error instanceof Error ? error : undefined\n        )\n      );\n    }\n  }\n\n  /**\n   * 验证评估请求\n   */\n  private validateRequest(request: EvaluationRequest): void {\n    if (!request.evaluationModelKey?.trim()) {\n      throw new EvaluationValidationError('Evaluation model key must not be empty.');\n    }\n\n    if (!request.mode) {\n      throw new EvaluationValidationError('Evaluation mode configuration must not be empty.');\n    }\n    if (!request.mode.functionMode) {\n      throw new EvaluationValidationError('Function mode must not be empty.');\n    }\n    if (!request.mode.subMode) {\n      throw new EvaluationValidationError('Sub mode must not be empty.');\n    }\n\n    switch (request.type) {\n      case 'result':\n        if (!request.target?.workspacePrompt?.trim()) {\n          throw new EvaluationValidationError('Workspace prompt must not be empty.');\n        }\n        this.validateTestCase(request.testCase, 'Result evaluation test case');\n        this.validateSnapshot(request.snapshot, 'Result evaluation snapshot');\n        if (request.snapshot.testCaseId !== request.testCase.id) {\n          throw new EvaluationValidationError(\n            'Result evaluation snapshot testCaseId must match testCase.id.'\n          );\n        }\n        if (this.isImageText2ImageMode(request) && !this.hasSnapshotOutputMedia(request.snapshot)) {","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L443-L479","documentation":"OptimizationError thrown by optimizeMessage when the model registry returns nothing for request.modelKey — the message-optimization counterpart of the 'Model not found' check in optimizePrompt. It fires after request validation but before template resolution.","triggerScenarios":"Calling optimizeMessage with a modelKey absent from the model manager: model deleted after selection, stale default, models not yet loaded, or key from another profile.","commonSituations":"Same as prompt-flow: deleted default model, imported settings referencing missing models, async model list races, key format mismatches.","solutions":["Validate the key against modelManager.listModels() before calling optimizeMessage.","Refresh the model list and re-select a valid model when the error occurs.","Await model-manager initialization before enabling message optimization in the UI.","Fall back to the first available model when the saved default is missing."],"exampleFix":"// before\nawait promptService.optimizeMessage({ selectedMessageId: id, messages, modelKey: staleKey });\n\n// after\nconst models = await modelManager.listModels();\nconst modelKey = models.some(m => m.key === staleKey) ? staleKey : models[0]?.key;\nif (!modelKey) throw new Error('No models configured');\nawait promptService.optimizeMessage({ selectedMessageId: id, messages, modelKey });","handlingStrategy":"validation","validationCode":"if (!(await modelManager.getModel(request.modelKey))) throw new Error('Model not configured');","typeGuard":"async function modelExists(modelManager: any, key: string): Promise<boolean> {\n  return !!(await modelManager.getModel(key));\n}","tryCatchPattern":"try { await svc.optimizeMessage(req); } catch (e) { if (e instanceof OptimizationError && e.message === 'Model not found') await refreshModels(); }","preventionTips":["Validate modelKey against the registry","Refresh model list when stale defaults are used","Await init before enabling message optimization"],"tags":["model-config","message-optimization","not-found"],"backgroundTag":"missing-model-key","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}