{"record":{"id":"df8875634cbd33c8","repo":"linshenkx/prompt-optimizer","slug":"variables-list-must-not-be-empty","errorCode":null,"errorMessage":"Variables list must not be empty.","messagePattern":"Variables list must not be empty\\.","errorType":"validation","errorClass":"VariableValueGenerationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/variable-value-generation/service.ts","lineNumber":85,"sourceCode":"      }\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  }\n\n  /**\n   * 验证模型是否存在\n   */\n  private async validateModel(modelKey: string): Promise<void> {\n    const model = await this.modelManager.getModel(modelKey);\n    if (!model) {\n      throw new VariableValueGenerationModelError(modelKey);","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/variable-value-generation/service.ts#L67-L103","documentation":"generate() needs at least one variable to generate values for; validateRequest throws when request.variables is undefined, null, or an empty array. Generating values with no variables is meaningless, so it is treated as a caller error before any model call is made.","triggerScenarios":"generate({ promptContent: 'x', generationModelKey: 'm', variables: [] }) or omitting the variables field entirely.","commonSituations":"Calling value generation before the extraction step has produced variables; UI flow letting users skip variable selection; a filter that removed all variables (e.g. only invalid names survived); state reset between extraction and generation steps.","solutions":["Ensure the variable-extraction step ran and produced at least one variable before invoking generate","Guard with an explicit check and skip/warn instead of calling generate with an empty list","Verify no upstream filter (dedupe, name validation) emptied the variables array"],"exampleFix":"// before\nawait gen.generate({ promptContent, generationModelKey, variables: extracted.variables });\n\n// after\nif (!extracted.variables?.length) {\n  return { skipped: true, reason: 'no variables extracted' };\n}\nawait gen.generate({ promptContent, generationModelKey, variables: extracted.variables });","handlingStrategy":"validation","validationCode":"if (!Array.isArray(req.variables) || req.variables.length === 0) { return skipGeneration('no variables'); }","typeGuard":"const hasVariables = (r: VariableValueGenerationRequest) => Array.isArray(r.variables) && r.variables.length > 0;","tryCatchPattern":"catch (e) { if (e instanceof VariableValueGenerationValidationError && /Variables list/.test(e.message)) return skip(); throw e; }","preventionTips":["Sequence your flow: extraction must succeed and yield variables before generation","Guard empty arrays as a no-op rather than an error path"],"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"}