code-debugging
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Debugging
代码调试
Systematically debug experiment code with structured error categorization and fix strategies.
通过结构化的错误分类和修复策略,系统性地调试实验代码。
Input
输入
- — Error message, stderr output, or code file with issues
$0 - — Optional: the code that produced the error
$1
- — 错误信息、stderr输出或存在问题的代码文件
$0 - — 可选:产生错误的代码
$1
References
参考资料
- Debug patterns and state machine:
~/.claude/skills/code-debugging/references/debug-patterns.md
- 调试模式与状态机:
~/.claude/skills/code-debugging/references/debug-patterns.md
Workflow
工作流
Step 1: Categorize the Error
步骤1:错误分类
| Category | Examples | Severity |
|---|---|---|
| SyntaxError | Invalid syntax, indentation | Low |
| ImportError | Missing module, wrong name | Low |
| RuntimeError | Division by zero, shape mismatch | Medium |
| TimeoutError | Infinite loop, too slow | Medium |
| OutputError | Missing files, wrong format | Medium |
| LogicError | Wrong results, 0% accuracy | High |
| 类别 | 示例 | 严重程度 |
|---|---|---|
| 语法错误 | 无效语法、缩进错误 | 低 |
| 导入错误 | 缺失模块、名称错误 | 低 |
| 运行时错误 | 除零错误、形状不匹配 | 中 |
| 超时错误 | 无限循环、运行过慢 | 中 |
| 输出错误 | 文件缺失、格式错误 | 中 |
| 逻辑错误 | 结果错误、准确率为0% | 高 |
Step 2: Analyze Root Cause
步骤2:分析根本原因
- Read the error traceback (last 1500 chars if truncated)
- Identify the exact line and variable causing the error
- Check for common patterns:
- Device mismatch (CPU vs GPU tensors)
- Shape mismatch in matrix operations
- Missing data normalization
- Off-by-one errors in indexing
- Incorrect loss function for task type
- 阅读错误回溯信息(如果被截断则取最后1500个字符)
- 定位导致错误的具体代码行和变量
- 检查常见问题模式:
- 设备不匹配(CPU与GPU张量)
- 矩阵运算中的形状不匹配
- 缺少数据归一化
- 索引中的差一错误
- 任务类型对应的损失函数不正确
Step 3: Apply Fix Strategy
步骤3:应用修复策略
For syntax/import errors: Direct fix, single attempt
For runtime errors: Fix and rerun, up to 4 retries
For logic errors: Reflect on approach, consider alternative methods
For timeout: Reduce dataset size, optimize bottleneck, add early stopping
针对语法/导入错误:直接修复,单次尝试
针对运行时错误:修复后重新运行,最多重试4次
针对逻辑错误:反思现有方法,考虑替代方案
针对超时错误:减小数据集规模,优化瓶颈,添加提前停止机制
Step 4: Reflect and Prevent
步骤4:反思与预防
After fixing:
- Explain why the error occurred
- Identify which lines caused it
- Describe the fix line-by-line
- Note patterns to avoid in future code
修复完成后:
- 解释错误发生的原因
- 定位导致错误的代码行
- 逐行描述修复内容
- 记录未来代码编写中需要避免的问题模式
Fix Strategy State Machine
修复策略状态机
Stage 0 (first attempt) → repost code as fresh
Stage 1 (second attempt) → repost or leave depending on severity
Stage 2 (third attempt) → regenerate from scratch if still failingStage 0 (first attempt) → repost code as fresh
Stage 1 (second attempt) → repost or leave depending on severity
Stage 2 (third attempt) → regenerate from scratch if still failingRules
规则
- Prefer minimal targeted edits over full rewrites
- Maximum 4-5 fix attempts before changing approach
- Always truncate long error outputs to last 1500 characters
- After fixing, verify the fix doesn't introduce new errors
- Keep error history to avoid repeating the same mistakes
- If 0% accuracy: check accuracy calculation first, then check data pipeline
- 优先进行最小化的针对性修改,而非完全重写
- 最多尝试4-5次修复后再更换方法
- 始终将过长的错误输出截断至最后1500个字符
- 修复完成后,验证修复不会引入新的错误
- 保留错误历史记录,避免重复犯相同的错误
- 如果准确率为0%:首先检查准确率计算逻辑,然后检查数据处理流程
Related Skills
相关技能
- Upstream: experiment-code
- See also: paper-to-code, data-analysis
- 上游技能:experiment-code
- 另见:paper-to-code、data-analysis