首页 全部提示词 Vibe Coding

处理功能中的 bug

handle bug in feature

文本 @dishantpatel624 1,385 字符 在 prompts.chat 查看 译文有问题?

中文译文

担任资深软件工程师和系统架构师。

背景

我是一名正在开发某个应用功能的开发者。

存在一个 bug,而之前的修复让系统变得更加复杂。

我需要:

  • 清晰理解系统流程
  • 定位确切的故障点
  • 最小化、精准的修复(不要过度设计)

你必须在尝试修复之前先解释系统。


输入

功能: ${describe_feature}

预期行为: ${what_should_happen}

实际问题: ${what_is_happening}

代码: ${paste_relevant_code}


输出格式(严格)

1. 系统流程(可视化 + 逻辑)

A. 流程图

提供清晰的逐步流程:

用户操作
→ UI 层
→ 状态 / 控制器 / 逻辑
→ 数据处理
→ 外部系统 / SDK / API(如有)
→ 响应处理
→ 渲染 / 输出
→ UI 更新


B. 解释每个阶段

对于每个步骤:

  • 发生了什么
  • 传递了什么数据
  • 发生了什么转换
  • 存在什么依赖

C. 关键时序点(重要)

识别:

  • 对象/资源何时被创建
  • 数据何时被加载或获取
  • 状态何时更新
  • 属性/配置应在何时被应用

2. 预期行为

定义正确行为:

  • 正常成功流程
  • 边界情况
  • 失败场景

如果不清楚,提出最多 3 个具体问题并停止。


3. 当前行为

使用以下内容解释实际行为:

  • 问题描述
  • 代码分析

4. 不匹配(关键)

识别:

  • 行为发生偏离的确切步骤
  • 应该发生什么 vs 实际发生了什么

5. 根本原因(精准)

识别确切原因:

  • 时序问题(异步、生命周期)
  • 引用或数据不正确
  • 状态未更新
  • 逻辑缺陷
  • 集成问题

指向:

  • 具体的函数 / 代码块 / 生命周期阶段

如果不确定,清楚说明假设。


6. 最小修复(严格)

  • 提供尽可能小的改动
  • 不要重写架构
  • 不要引入不必要的抽象

仅提供修改后的代码片段。

重点关注:

  • 修复时序
  • 正确的数据流
  • 正确的状态更新

7. 为什么修复有效

解释:

  • 它如何修复确切的故障点
  • 与系统流程的关系
  • 与生命周期/时序的关系

8. 风险(重要)

分析:

  • 对系统其他部分的影响
  • 性能影响
  • 副作用

9. 预防(架构指导)

建议:

  • 更好的生命周期处理
  • 清晰的职责分离
  • 逻辑应该放在哪里:
    • UI
    • 控制器 / 状态
    • 数据 / 服务层

约束

  • 不要在没有说明假设的情况下假定行为
  • 不要随意移动逻辑
  • 不要盲目添加条件
  • 专注于流程、时序和数据

回退规则

如果输入不足:

  • 提出最多 3 个具体问题
  • 停止

自检(强制)

在回答之前:

  • 我是否将 bug 映射到了具体的流程步骤?
  • 我是否识别出了时序/生命周期问题?
  • 修复是否最小化且有范围限定?
  • 我是否避免了过度设计?

English original

Act as a senior software engineer and system architect.

Context

I am a developer working on an application feature.

There is a bug, and previous fixes made the system more complex.

I need:

  • Clear understanding of the system flow
  • Identification of the exact failure point
  • Minimal, precise fix (no over-engineering)

You MUST explain the system before attempting a fix.


Inputs

Feature: ${describe_feature}

Expected Behavior: ${what_should_happen}

Actual Issue: ${what_is_happening}

Code: ${paste_relevant_code}


Output Format (STRICT)

1. System Flow (Visual + Logical)

A. Flow Diagram

Provide a clear step-by-step flow:

User Action
→ UI Layer
→ State / Controller / Logic
→ Data Processing
→ External System / SDK / API (if any)
→ Response Handling
→ Rendering / Output
→ UI Update


B. Explain Each Stage

For each step:

  • What happens
  • What data is passed
  • What transformations occur
  • What dependencies exist

C. Critical Timing Points (IMPORTANT)

Identify:

  • When objects/resources are created
  • When data is loaded or fetched
  • When state updates occur
  • When properties/configuration SHOULD be applied

2. Expected Behavior

Define correct behavior:

  • Normal success flow
  • Edge cases
  • Failure scenarios

If unclear, ask up to 3 specific questions and STOP.


3. Current Behavior

Explain actual behavior using:

  • Issue description
  • Code analysis

4. Mismatch (Critical)

Identify:

  • Exact step where behavior diverges
  • What should happen vs what actually happens

5. Root Cause (Precise)

Identify the exact reason:

  • Timing issue (async, lifecycle)
  • Incorrect reference or data
  • State not updating
  • Logic flaw
  • Integration issue

Point to:

  • Specific function / block / lifecycle stage

If unsure, clearly state assumptions.


6. Minimal Fix (STRICT)

  • Provide smallest possible change
  • Do NOT rewrite architecture
  • Do NOT introduce unnecessary abstraction

Provide ONLY modified code snippet.

Focus on:

  • Fixing timing
  • Correct data flow
  • Proper state update

7. Why Fix Works

Explain:

  • How it fixes the exact failure point
  • Relation to system flow
  • Relation to lifecycle/timing

8. Risks (IMPORTANT)

Analyze:

  • Impact on other parts of system
  • Performance implications
  • Side effects

9. Prevention (Architecture Guidance)

Suggest:

  • Better lifecycle handling
  • Clear separation of responsibilities
  • Where logic should live:
    • UI
    • Controller / State
    • Data / Service layer

Constraints

  • Do NOT assume behavior without stating assumptions
  • Do NOT move logic randomly
  • Do NOT add conditions blindly
  • Focus on flow, timing, and data

Fallback Rule

If inputs are insufficient:

  • Ask up to 3 specific questions
  • STOP

Self-Check (MANDATORY)

Before answering:

  • Did I map the bug to a specific flow step?
  • Did I identify timing/lifecycle issues?
  • Is the fix minimal and scoped?
  • Did I avoid over-engineering?