{"record":{"id":"4028992641f1cb6e","repo":"YMFE/yapi","slug":"plugin-route-config-error-402899","errorCode":null,"errorMessage":"Plugin Route config Error","messagePattern":"Plugin Route config Error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/websocket.js","lineNumber":13,"sourceCode":"const koaRouter = require('koa-router');\nconst interfaceController = require('./controllers/interface.js');\nconst yapi = require('./yapi.js');\n\nconst router = koaRouter();\nconst { createAction } = require(\"./utils/commons.js\")\n\nlet pluginsRouterPath = [];\n\n\nfunction addPluginRouter(config) {\n  if (!config.path || !config.controller || !config.action) {\n    throw new Error('Plugin Route config Error');\n  }\n  let method = config.method || 'GET';\n  let routerPath = '/ws_plugin/' + config.path;\n  if (pluginsRouterPath.indexOf(routerPath) > -1) {\n    throw new Error('Plugin Route path conflict, please try rename the path')\n  }\n  pluginsRouterPath.push(routerPath);\n  createAction(router, \"/api\", config.controller, config.action, routerPath, method, true);\n}\n\n\nfunction websocket(app) {\n  createAction(router, \"/api\", interfaceController, \"solveConflict\", \"/interface/solve_conflict\", \"get\")\n\n  yapi.emitHookSync('add_ws_router', addPluginRouter);\n\n\n  app.ws.use(router.routes())","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/server/websocket.js#L1-L31","documentation":"addPluginRouter() in server/websocket.js throws 'Plugin Route config Error' when a plugin's websocket route config lacks path, controller, or action. It is a fail-fast config validation for plugin-registered ws routes.","triggerScenarios":"A plugin calls addPluginRouter({path:'x'}) missing controller or action, or calls addPluginRouter(undefined/null config), usually via a malformed plugin config in the plugin module's exported route list.","commonSituations":"Typo in plugin config keys (e.g. `handlers` instead of `controller`); plugin version mismatch with yapi plugin API; config object built conditionally so some fields end up undefined.","solutions":["Open the plugin's config and ensure every route entry has non-empty path, controller, and action","Log the config object before addPluginRouter to see which field is missing","Fix the key spelling to match the expected schema (path/controller/action/method)","Update or reinstall the plugin to a version compatible with the current yapi"],"exampleFix":"// before\naddPluginRouter({ path: 'status', controller: myController });\n// after\naddPluginRouter({ path: 'status', controller: myController, action: 'getStatus', method: 'GET' });","handlingStrategy":"validation","validationCode":"function assertWsRouteConfig(config){\n  ['path','controller','action'].forEach(k => {\n    if (!config || !config[k]) throw new Error(`plugin ws route missing required field: ${k}`);\n  });\n}","typeGuard":"function isValidPluginRouteConfig(c){\n  return !!c && typeof c.path === 'string' && c.path.length > 0\n    && typeof c.controller !== 'undefined' && c.controller !== null\n    && typeof c.action === 'string' && c.action.length > 0;\n}","tryCatchPattern":"try {\n  addPluginRouter(config);\n} catch (e) {\n  if (e.message === 'Plugin Route config Error') {\n    console.error('Invalid ws plugin route config:', JSON.stringify(config));\n  } else throw e;\n}","preventionTips":["Validate plugin route configs at plugin load time with a schema check","Keep plugin route config keys exactly path/controller/action/method","Pin plugin versions and re-check configs after yapi upgrades"],"tags":["plugin","websocket","configuration"],"backgroundTag":"plugin-config-invalid","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}