{"record":{"id":"7a733471ba8ee7ea","repo":"YMFE/yapi","slug":"hookname-7a7334","errorCode":null,"errorMessage":"不存在的hookname","messagePattern":"不存在的hookname","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/plugin.js","lineNumber":197,"sourceCode":"\n  /**\n   * addNoticePlugin(config)\n   * \n   * config.weixin = {\n   *    title: 'wechat',\n   *    hander: (emails, title, content)=> {...}\n   * }\n   */\n  addNotice:{\n    type: 'multi',\n    listener: []\n  }\n};\n\nfunction bindHook(name, listener) {\n  if (!name) throw new Error('缺少hookname');\n  if (name in hooks === false) {\n    throw new Error('不存在的hookname');\n  }\n  if (hooks[name].type === 'multi') {\n    hooks[name].listener.push(listener);\n  } else {\n    if (typeof hooks[name].listener === 'function') {\n      throw new Error('重复绑定singleHook(' + name + '), 请检查');\n    }\n    hooks[name].listener = listener;\n  }\n}\n\n/**\n *\n * @param {*} hookname\n * @return promise\n */\nfunction emitHook(name) {\n  if (hooks[name] && typeof hooks[name] === 'object') {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/server/plugin.js#L179-L215","documentation":"bindHook validates the name against the known hooks map; if the hookname is not registered it throws '不存在的hookname'. YApi only supports a fixed set of hook points, so plugins must bind to existing ones.","triggerScenarios":"yapi.bindHook('some_typo_or_invented_hook', fn) where the name is absent from the hooks object in server/plugin.js.","commonSituations":"Plugin written for a different YApi version whose hook names differ; misspelled hook name; copying hook names from docs of another project.","solutions":["Use an existing hook name from the hooks registry in server/plugin.js.","Check YApi version compatibility — hook names change across versions.","Grep the codebase for 'bindHook(' usages to see valid names."],"exampleFix":"// before\nyapi.bindHook('interface_add', handler); // not a real hook\n// after\nyapi.bindHook('add_router', handler);","handlingStrategy":"validation","validationCode":"const knownHooks = ['add_router', 'interface_save', 'project_add', 'init', ...]; // from server/plugin.js\nif (!knownHooks.includes(name)) throw new Error(`Unknown hook: ${name}`);","typeGuard":"function isRegisteredHook(name, hooks) {\n  return typeof name === 'string' && name in hooks;\n}","tryCatchPattern":"try {\n  yapi.bindHook(name, listener);\n} catch (e) {\n  if (e.message === '不存在的hookname') {\n    console.error(`Hook \"${name}\" not supported in this YApi version`);\n  } else { throw e; }\n}","preventionTips":["Copy hook names from the hooks registry in server/plugin.js, not memory.","Verify hook names when upgrading YApi versions.","Read existing plugins for canonical hook usage examples."],"tags":["plugin","hooks","invalid-name"],"backgroundTag":"unknown-hook-name","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}