{"record":{"id":"543506693963c8e9","repo":"linshenkx/prompt-optimizer","slug":"prompt-content-must-not-be-empty-543506","errorCode":null,"errorMessage":"Prompt content must not be empty.","messagePattern":"Prompt content must not be empty\\.","errorType":"validation","errorClass":"VariableValueGenerationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/variable-value-generation/service.ts","lineNumber":77,"sourceCode":"      const result = await this.llmService.sendMessage(messages, request.generationModelKey);\n\n      // 7. 解析 LLM 返回的 JSON 结果（传递请求的变量列表用于对齐校验）\n      return this.parseGenerationResult(result, request.variables);\n    } catch (error) {\n      // 🔧 修复：保留原始错误类型，不要过度包装\n      if (error instanceof VariableValueGenerationError) {\n        throw error;\n      }\n      throw new VariableValueGenerationExecutionError(error instanceof Error ? error.message : String(error))\n    }\n  }\n\n  /**\n   * 验证请求参数\n   */\n  private validateRequest(request: VariableValueGenerationRequest): void {\n    if (!request.promptContent?.trim()) {\n      throw new VariableValueGenerationValidationError('Prompt content must not be empty.');\n    }\n\n    if (!request.generationModelKey?.trim()) {\n      throw new VariableValueGenerationValidationError('Generation model key must not be empty.');\n    }\n\n    if (!request.variables || request.variables.length === 0) {\n      throw new VariableValueGenerationValidationError('Variables list must not be empty.');\n    }\n\n    // 验证每个变量\n    for (let i = 0; i < request.variables.length; i++) {\n      const variable = request.variables[i];\n      if (!variable.name?.trim()) {\n        throw new VariableValueGenerationValidationError(`Variable at index ${i} has empty name.`);\n      }\n    }\n  }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/variable-value-generation/service.ts#L59-L95","documentation":"validateRequest (called at the start of generate) rejects requests whose promptContent is null, undefined, or whitespace-only. The prompt content is the input the model generates variable values from, so an empty prompt is a caller bug, not a model failure.","triggerScenarios":"Calling generate({ promptContent: '', generationModelKey: 'gpt', variables: [...] }) or passing promptContent: undefined / '   '.","commonSituations":"Upstream UI letting users submit an empty prompt; reading promptContent from a file/env var that is missing; refactoring that renamed the field; passing the wrong object into generate().","solutions":["Check promptContent?.trim() before calling generate and surface a user-facing validation message","Fix the data source that produced an empty prompt (file read, form field, state)","Ensure you are passing the full request object with the correct property names"],"exampleFix":"// before\nawait gen.generate({ promptContent: savedPrompt, ...req }); // savedPrompt may be ''\n\n// after\nconst promptContent = savedPrompt?.trim();\nif (!promptContent) throw new Error('Prompt is required before generating variable values');\nawait gen.generate({ ...req, promptContent });","handlingStrategy":"validation","validationCode":"if (!req.promptContent?.trim()) throw new Error('Prompt content required');","typeGuard":"const hasPrompt = (r: VariableValueGenerationRequest) => typeof r.promptContent === 'string' && r.promptContent.trim().length > 0;","tryCatchPattern":"catch (e) { if (e instanceof VariableValueGenerationValidationError && /Prompt content/.test(e.message)) return badRequest('prompt required'); throw e; }","preventionTips":["Validate form/state at the UI layer so empty prompts never reach the service","Trim user input before building the request"],"tags":["request-validation","empty-input","variable-value-generation"],"backgroundTag":"invalid-request-parameters","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}