Files
bigwo/dev-assistant-mcp/dist/resources/debugGuide.js
2026-03-12 12:47:56 +08:00

52 lines
1.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const debugGuideResource = {
uri: "devassistant://resources/debug-guide",
name: "调试指南",
description: "常见错误模式和排查方法",
mimeType: "text/markdown",
};
export function getDebugGuide() {
return `# 调试指南
## 调试步骤
1. **复现问题** — 找到稳定的复现路径
2. **阅读错误信息** — 仔细看完整报错和堆栈
3. **缩小范围** — 二分法定位问题代码
4. **检查假设** — 用 console.log / print 验证变量值
5. **查看变更** — git diff 看最近改了什么
6. **搜索已知问题** — Google / StackOverflow / GitHub Issues
## 常见错误模式
### TypeError: Cannot read properties of undefined
- **原因**:访问了 null/undefined 的属性
- **排查**:检查调用链上哪个变量可能为空
- **修复**:使用可选链 \`?.\` 或提前判空
### ECONNREFUSED / ETIMEDOUT
- **原因**:网络连接被拒绝或超时
- **排查**:检查目标服务是否启动、端口是否正确、防火墙规则
- **修复**:确认服务地址和端口,添加重试机制
### Memory Leak
- **表现**:内存持续增长不释放
- **排查**:检查未清理的定时器、事件监听器、闭包引用
- **修复**:在组件销毁/函数退出时清理资源
### Race Condition
- **表现**:偶发的数据不一致
- **排查**:检查并发操作共享状态
- **修复**:加锁、使用原子操作、或重新设计数据流
### Import/Module Error
- **原因**:路径错误、循环依赖、导出方式不匹配
- **排查**检查文件路径、ESM vs CJS、default vs named export
- **修复**:修正导入路径和方式
## 调试工具
- **Node.js**: \`node --inspect\`, Chrome DevTools
- **Python**: \`pdb\`, \`ipdb\`, VS Code debugger
- **浏览器**: Chrome DevTools (Sources, Network, Console)
- **通用**: \`git bisect\` 定位引入 bug 的提交
`;
}
//# sourceMappingURL=debugGuide.js.map