{"record":{"id":"6cbe70b96353759c","repo":"iflytek/astron-agent","slug":"codeenums-serviceparamserror","errorCode":"CodeEnums.ServiceParamsError","errorMessage":"text不能为空","messagePattern":"text不能为空","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"core/plugin/aitools/service/smart_tts/smart_tts_service.py","lineNumber":91,"sourceCode":"    path=\"/aitools/v1/smarttts\",\n    query=None,\n    body=SmartTTSInput,\n    response=BaseResponse,\n    summary=\"Smart TTS\",\n    description=\"Convert text to speech\",\n    tags=[\"public_cn\"],\n    deprecated=False,\n)\nasync def smart_tts_service(\n    body: SmartTTSInput,\n    request: Request,\n    span: Optional[SpanLike] = None,\n    meter: Optional[Meter] = None,\n    node_trace: Optional[NodeTraceLog] = None,\n) -> BaseResponse:\n    \"\"\"Smart TTS Service\"\"\"\n    if not body.text:\n        raise ServiceException.from_error_code(\n            CodeEnums.ServiceParamsError, extra_message=\"text不能为空\"\n        )\n\n    url = os.getenv(TTS_URL_KEY, \"\")\n    credentials = get_iflytek_open_platform_credentials()\n    data = gen_data(credentials.app_id, body.text, body.vcn, body.speed)\n\n    audio_data = bytearray()\n    async with WebSocketClient(\n        url=url,\n        span=span,\n        auth=\"ASE\",\n        app_id=credentials.app_id,\n        api_key=credentials.api_key,\n        api_secret=credentials.api_secret,\n    ).start() as client:\n        await client.send(json.dumps(data))\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/service/smart_tts/smart_tts_service.py#L73-L109","documentation":"The Smart TTS service rejects a request whose `body.text` is missing, None, or an empty string before doing any work. Since text is the sole required input for text-to-speech synthesis, the service fails fast with ServiceParamsError to avoid a pointless (and costly) call to the iFlytek TTS backend. The check `if not body.text` treats empty strings and None identically.","triggerScenarios":"Calling smart_tts_service with a SmartTTSRequest whose `text` field is None, empty string \"\", or a falsy value; e.g. POSTing to the smart-TTS endpoint with an omitted or blank `text` JSON field.","commonSituations":"Frontend sends the request before the user types anything; an upstream workflow node passes an empty LLM output as the TTS input; a caller strips/normalizes text and accidentally empties it; schema changes rename the field so text is never populated.","solutions":["Ensure the `text` field is populated with non-empty content in the request body before invoking the smart TTS endpoint.","Add client-side validation on the caller (form/workflow node) that blocks empty or whitespace-only text with a friendlier message.","If text comes from a previous pipeline step, log/inspect that step's output to find why it produced empty text.","Consider trimming whitespace on the caller side and rejecting whitespace-only strings early so the user sees a clear validation error."],"exampleFix":"// before\nawait api.post('/plugin/aitools/smart_tts', { vcn: 'xiaoyan', speed: 50 });\n// after\nconst text = userInput.trim();\nif (!text) throw new Error('Please provide text to synthesize');\nawait api.post('/plugin/aitools/smart_tts', { text, vcn: 'xiaoyan', speed: 50 });","handlingStrategy":"validation","validationCode":"def can_call_smart_tts(body) -> bool:\n    return bool(body and getattr(body, 'text', None) and body.text.strip())","typeGuard":"def has_text(body) -> bool:\n    return isinstance(getattr(body, 'text', None), str) and body.text.strip() != ''","tryCatchPattern":"try:\n    resp = await smart_tts_service(body, request)\nexcept ServiceException as e:\n    if e.code == CodeEnums.ServiceParamsError:\n        return error_response('请输入需要合成的文本', 400)\n    raise","preventionTips":["Validate text is non-empty and non-whitespace in the UI/form before submitting.","Add a shared request-preflight check for required fields in workflow nodes feeding TTS.","Trim user input before constructing SmartTTSRequest."],"tags":["validation","tts","request-params"],"backgroundTag":"empty-required-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}