
Promise(…).catch does not work for Error: There is no endpoint matching that name of fn_index matching that number.
快速结论:该报错出现在使用 Gradio Client 的 predict() 或 submit() 方法时,前端传入的 API 端点名称或编号无效。错误在 Promise 链外层同步抛出,导致 .catch() 和 try-catch 都无法捕获,表现为未处理的 Promise 拒绝。
问题场景
用户在一个基于 Next.js 的 Web 应用中,通过 @gradio/client 调用远程 Gradio 服务的 API 端点(例如 /api/gradio/[name].tsx),传入的端点名或 fn_index 在服务端不存在,导致 get_endpoint_info() 同步抛出错误,进而触发 Node.js 的 unhandledRejection。已知复现工具包括 tts-generation-webui 以及其它通过 Gradio Client 进行远程调用的脚本。
报错原文
Submit function encountered an error: Error: There is no endpoint matching that name of fn_index matching that number.
at get_endpoint_info (file:///C:/Users/user/Desktop/tts-generation-webui-main/react-ui/node_modules/@gradio/client/dist/index.js:2255:11)
at Client.submit (file:///C:/Users/user/Desktop/tts-generation-webui-main/react-ui/node_modules/@gradio/client/dist/index.js:1601:51)
at file:///C:/Users/user/Desktop/tts-generation-webui-main/react-ui/node_modules/@gradio/client/dist/index.js:971:22
at new Promise ()
at Client.predict (file:///C:/Users/user/Desktop/tts-generation-webui-main/react-ui/node_modules/@gradio/client/dist/index.js:970:10)
at eval (webpack-internal:///(api)/./src/pages/api/gradio/[name].tsx:83:62)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async handler (webpack-internal:///(api)/./src/pages/api/gradio/[name].tsx:51:24)
⨯ unhandledRejection: Error: There is no endpoint matching that name of fn_index matching that number.
at get_endpoint_info (file:///C:/Users/user/Desktop/tts-generation-webui-main/react-ui/node_modules/@gradio/client/dist/index.js:2255:11)
at Client.submit (file:///C:/Users/user/Desktop/tts-generation-webui-main/react-ui/node_modules/@gradio/client/dist/index.js:1601:51)
...
原因分析
经 Issue 贡献者分析,问题出在 @gradio/client 库内部的错误处理机制:
get_endpoint_info()函数在client.predict()或client.submit()被调用的 Promise 链之外同步抛出Error,导致该错误脱离 Promise 的.catch()捕获范围。- 由于错误并未被包装为
Promise.reject(),.catch()和try-catch(在 async 函数中使用)均无法处理该异常,最终触发 Node.js 的unhandledRejection。 - 可能原因:客户端传入的端点名称(
name)或fn_index与 Gradio 服务端返回的端点列表不匹配,例如服务端版本更新导致端点名称变更,或是客户端缓存了过期的端点信息。
环境排查
- Gradio 版本:确认
@gradio/client的版本(未在 Issue 中明确,但可检查package.json)。 - Node.js 版本:使用者环境中的 Node.js 版本(上述栈追踪使用 Node.js)。
- Gradio 服务端:远程 Gradio 服务的版本及运行状态,确认端点列表是否包含所请求的
name或fn_index。 - 调用方式:确认客户端是使用
client.predict()、client.submit()还是更低阶的 API。
解决步骤
- 核对端点名称:直接通过浏览器访问 Gradio 服务(例如
http://localhost:7770/)或使用 Gradio 的 API 文档页面,确认可用的端点名称和对应的fn_index。在 Issue 中,评论中提到“直接访问 http://localhost:7770/ 并安装扩展”曾作为临时工作区。 - 包装调用逻辑(可优先尝试):将
client.predict()或client.submit()放入async函数并使用try-catch,如果错误仍是未处理,则在调用前显式验证端点是否存在:const endpoints = await client.view_api(); // 获取所有可用端点 // 在调用前检查端点名称或 fn_index 是否存在 if (!endpoints.some(ep => ep.name === targetName || ep.index === targetIndex)) { throw new Error(`Endpoint ${targetName} or index ${targetIndex} not found`); } - 确保错误被 Promise 包装:如果开发环境允许,在调用
get_endpoint_info()之前,将可能同步抛出的错误显式转为Promise.reject()(这需要修改@gradio/client源码或提交 PR)。Issue 中建议的修复方向包括:- 在
client.connect()阶段预验证端点可用性。 - 将
get_endpoint_info()内的同步throw改为return Promise.reject(new Error(...))。
- 在
- 升级或等待修复:检查
@gradio/client是否有更新版本包含对此错误的修复。如果无法修改客户端代码,可临时在全局监听unhandledRejection事件避免进程崩溃:process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Rejection at:', promise, 'reason:', reason); // 可选:尝试重试或记录日志 }); - 若使用 Next.js:确保 API 路由(如
[name].tsx)中正确传递fn_index和name,检查是否有拼写错误或动态路由参数解析问题。
验证方法
修复后,调用之前触发报错的 client.predict() 或 client.submit():
- 如果使用
.catch(),错误应被正常捕获,不再出现unhandledRejection。 - 如果使用
async/await配合try-catch,catch块应能收到"There is no endpoint matching that name of fn_index matching that number."错误对象。 - Node.js 进程不应崩溃,全局
unhandledRejection事件数量为零。


![[Bug]: Why does ragflow have to reload and download this bunch of things every time it restarts? I used to remember it would restart directl](https://www.chat-gpts.plus/wp-content/uploads/2026/07/13026-44b79dff-768x403.jpg)
