Best for
- Use this skill when debugging code, fixing test failures, addressing GitHub issues, resolving runtime errors, or patching security vulnerabilities.
ArabelaTso/Skills-4-SE/skills/bug-to-patch-generator/SKILL.md
Generate code fixes and patches from bug reports, failing test cases, error messages, and stack traces. Use this skill when debugging code, fixing test failures, addressing GitHub issues, resolving runtime errors, or patching security vulnerabilities. Analyzes the bug context, identifies root causes, and generates precise code patches with explanations and validation steps.
Decision brief
Automatically generate code fixes from bug reports, failing tests, error messages, and stack traces. Analyzes bug context, identifies root causes, and produces verified patches.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill "skills/bug-to-patch-generator"Inspect the Agent Skill "bug-to-patch-generator" from https://github.com/ArabelaTso/Skills-4-SE/blob/4f38503747e0617504bce5329283ef837d375c09/skills/bug-to-patch-generator/SKILL.md at commit 4f38503747e0617504bce5329283ef837d375c09. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
Collect all relevant information:
Collect all relevant information:
Identify the root cause:
Find the code that needs fixing:
Create minimal, focused fix:
Permission review
The documentation asks the agent to read local files, directories, or repositories.
# Read the source fileEvidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 90/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 236 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Automatically generate code fixes from bug reports, failing tests, error messages, and stack traces. Analyzes bug context, identifies root causes, and produces verified patches.
Understand bugs from multiple sources:
Determine the underlying issue:
Create targeted fixes:
Ensure fix correctness:
Collect all relevant information:
From failing tests:
FAILED tests/test_calculator.py::test_divide - ZeroDivisionError: division by zero
def test_divide():
result = divide(10, 0)
assert result == None # Expected to return None for division by zero
From error messages:
Traceback (most recent call last):
File "app.py", line 42, in process_data
result = data[index]
IndexError: list index out of range
From bug reports:
Title: App crashes when processing empty file
Steps to reproduce:
1. Upload empty CSV file
2. Click "Process"
3. App crashes with NoneType error
Expected: Error message shown to user
Actual: Application crashes
Identify the root cause:
Questions to answer:
Common bug patterns:
Find the code that needs fixing:
# Read the source file
def divide(a, b):
return a / b # Bug: No check for b == 0
Context needed:
Create minimal, focused fix:
Patch format:
# Before (buggy code)
def divide(a, b):
return a / b
# After (fixed code)
def divide(a, b):
if b == 0:
return None # or raise ValueError("Cannot divide by zero")
return a / b
Patch components:
Ensure correctness:
Validation steps:
# Test that should now pass
def test_divide_by_zero():
assert divide(10, 0) is None
# Additional tests for edge cases
def test_divide_normal():
assert divide(10, 2) == 5
def test_divide_negative():
assert divide(-10, 2) == -5
Verification checklist:
Bug report:
AttributeError: 'NoneType' object has no attribute 'upper'
Buggy code:
def format_name(name):
return name.upper()
Root cause: No validation for None input
Patch:
def format_name(name):
if name is None:
return "" # or raise ValueError("Name cannot be None")
return name.upper()
Explanation:
Alternative approaches:
# Option 1: Raise exception
def format_name(name):
if name is None:
raise ValueError("Name cannot be None")
return name.upper()
# Option 2: Use default parameter
def format_name(name=None):
return (name or "").upper()
# Option 3: Type hint and early return
def format_name(name: str | None) -> str:
if not name:
return ""
return name.upper()
Bug report:
IndexError: list index out of range
Failing test:
def test_get_last_element():
arr = [1, 2, 3]
assert get_element(arr, 3) == 3 # Want last element
Buggy code:
def get_element(arr, index):
return arr[index] # index 3 is out of bounds for length 3
Root cause: Confusion between length and index (0-based)
Patch:
def get_element(arr, index):
if index < 0 or index >= len(arr):
raise IndexError(f"Index {index} out of range for array of length {len(arr)}")
return arr[index]
Explanation:
Better alternative:
def get_element(arr, index):
"""Get element at index. Supports negative indexing."""
try:
return arr[index]
except IndexError:
raise IndexError(f"Index {index} out of range for array of length {len(arr)}")
Bug report:
Application crashes when file doesn't exist
FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
Buggy code:
def load_config():
with open('config.json') as f:
return json.load(f)
Root cause: No handling for missing file
Patch:
def load_config():
try:
with open('config.json') as f:
return json.load(f)
except FileNotFoundError:
# Return default config
return {"debug": False, "port": 8080}
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON in config.json: {e}")
Explanation:
Alternative with logging:
import logging
def load_config():
try:
with open('config.json') as f:
return json.load(f)
except FileNotFoundError:
logging.warning("config.json not found, using defaults")
return {"debug": False, "port": 8080}
except json.JSONDecodeError as e:
logging.error(f"Invalid JSON in config.json: {e}")
raise
Failing test:
def test_is_even():
assert is_even(0) == True # FAILS
assert is_even(2) == True
assert is_even(3) == False
Buggy code:
def is_even(n):
if n % 2: # Bug: 0 % 2 == 0 which is falsy
return False
return True
Root cause: Incorrect boolean logic (0 is falsy)
Patch:
def is_even(n):
return n % 2 == 0 # Explicitly check equality
Explanation:
Bug report:
Intermittent test failure in multithreaded code
AssertionError: Expected counter=1000, got counter=987
Buggy code:
class Counter:
def __init__(self):
self.count = 0
def increment(self):
self.count += 1 # Not atomic!
Root cause: Non-atomic operation in concurrent context
Patch (Python):
import threading
class Counter:
def __init__(self):
self.count = 0
self.lock = threading.Lock()
def increment(self):
with self.lock:
self.count += 1
Alternative using atomic operations:
from threading import Lock
from threading import local
class Counter:
def __init__(self):
self.count = 0
self._lock = Lock()
def increment(self):
with self._lock:
self.count += 1
# Or use atomic integer
from threading import Lock
class Counter:
def __init__(self):
from queue import Queue
self._queue = Queue()
self.count = 0
# Better: use threading.local or atomic types
import threading
class AtomicCounter:
def __init__(self):
self._value = 0
self._lock = threading.Lock()
def increment(self):
with self._lock:
self._value += 1
return self._value
@property
def value(self):
with self._lock:
return self._value
Bug report:
Application memory usage grows unbounded
Memory increases by ~100MB every hour
Buggy code:
class Cache:
def __init__(self):
self.data = {}
def store(self, key, value):
self.data[key] = value # Never clears old entries
def get(self, key):
return self.data.get(key)
Root cause: Unbounded cache growth
Patch:
from collections import OrderedDict
class Cache:
def __init__(self, max_size=1000):
self.data = OrderedDict()
self.max_size = max_size
def store(self, key, value):
if key in self.data:
# Move to end (most recently used)
self.data.move_to_end(key)
else:
self.data[key] = value
# Evict oldest if over limit
if len(self.data) > self.max_size:
self.data.popitem(last=False)
def get(self, key):
if key in self.data:
# Move to end (most recently used)
self.data.move_to_end(key)
return self.data[key]
return None
Explanation:
Failing test:
def test_invalid_input():
with pytest.raises(ValueError):
process(-1) # FAILS: raises TypeError instead
Buggy code:
def process(value):
if value < 0:
raise TypeError("Value must be non-negative") # Wrong exception type
return value * 2
Root cause: Using TypeError instead of ValueError
Patch:
def process(value):
if value < 0:
raise ValueError("Value must be non-negative") # Correct exception
return value * 2
Explanation:
## Bug Fix: [Short description]
### Bug Details
- **Location:** [file:line]
- **Error:** [error message or test failure]
- **Root Cause:** [explanation of the underlying issue]
- **Severity:** [Critical/High/Medium/Low]
### Analysis
[Detailed explanation of why the bug occurs]
### Proposed Fix
#### Changes
```[language]
# File: [filename]
# Before (lines X-Y)
[buggy code]
# After
[fixed code]
[Why this fix works and what it does]
[test code that validates the fix]
### Example Complete Patch
```markdown
## Bug Fix: Handle division by zero in calculator
### Bug Details
- **Location:** src/calculator.py:15
- **Error:** `ZeroDivisionError: division by zero`
- **Root Cause:** Missing validation for zero divisor
- **Severity:** High (causes crash)
### Analysis
The `divide` function performs division without checking if the divisor is zero.
When called with b=0, Python raises ZeroDivisionError, crashing the application.
The function should either return None, return infinity, or raise a custom exception
with a clear message.
### Proposed Fix
#### Changes
```python
# File: src/calculator.py
# Before (lines 14-15)
def divide(a, b):
return a / b
# After
def divide(a, b):
"""Divide a by b. Returns None if b is zero."""
if b == 0:
return None
return a / b
Added a check for zero divisor before performing division. Returns None to indicate invalid operation, which is consistent with other error cases in the codebase. This prevents the uncaught exception and allows callers to handle the None return.
Raise custom exception: raise ValueError("Cannot divide by zero")
Return float('inf'): Mathematical infinity
Return 0: Default to zero
Chosen approach: Return None because it's consistent with the existing codebase pattern of returning None for invalid operations.
# tests/test_calculator.py
def test_divide_by_zero():
"""Test that division by zero returns None."""
assert divide(10, 0) is None
assert divide(0, 0) is None
assert divide(-5, 0) is None
def test_divide_normal():
"""Test normal division still works."""
assert divide(10, 2) == 5
assert divide(10, 3) == pytest.approx(3.333, rel=0.001)
pytest tests/test_calculator.py::test_dividepytestdivide(10, 0) should return Nonemodulo function for same issuepower function may have similar edge cases (0^0, 0^-1)
## Best Practices
1. **Minimal changes** - Fix only what's broken, don't refactor unnecessarily
2. **Preserve behavior** - Ensure fix doesn't break working functionality
3. **Clear explanations** - Explain why the bug occurred and how fix addresses it
4. **Test thoroughly** - Add tests that would have caught the bug
5. **Consider alternatives** - Present multiple fix options when applicable
6. **Document the fix** - Add comments explaining non-obvious fixes
7. **Check for similar bugs** - Look for the same pattern elsewhere
8. **Validate edge cases** - Ensure fix handles all scenarios
9. **Follow code style** - Match existing patterns and conventions
10. **Suggest improvements** - Note related technical debt if relevant
## Common Pitfalls to Avoid
### Pitfall 1: Over-fixing
```python
# Bad: Refactoring unrelated code
def divide(a, b):
# Also renamed parameters and restructured
if divisor == 0:
return None
quotient = dividend / divisor
return quotient
# Good: Minimal fix
def divide(a, b):
if b == 0:
return None
return a / b
# Bad: Fix creates new issue
def get_first(arr):
if len(arr) == 0:
return None
return arr[1] # Bug! Should be arr[0]
# Good: Correct fix
def get_first(arr):
if len(arr) == 0:
return None
return arr[0]
# Bad: Silencing exceptions
def load_data():
try:
return dangerous_operation()
except Exception:
return None # Hides the actual error!
# Good: Specific exception handling
def load_data():
try:
return dangerous_operation()
except FileNotFoundError:
return None # Expected case
# Let other exceptions propagate
For language-specific bug patterns and fixes:
Frequently asked questions
Automatically generate code fixes from bug reports, failing tests, error messages, and stack traces. Analyzes bug context, identifies root causes, and produces verified patches.
The source record exposes this install command: npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill "skills/bug-to-patch-generator". Inspect the command and pinned source before running it.
Static rules flagged read-files in the source; the page lists the matching lines and excerpts.
Alternatives
alirezarezvani/claude-skills
App Store Optimization (ASO) toolkit for researching keywords, analyzing competitor rankings, generating metadata suggestions, and improving app visibility on Apple App Store and Google Play Store. Use when the user asks about ASO, app store rankings, app metadata, app titles and descriptions, app store listings, app visibility, or mobile app marketing on iOS or Android. Supports keyword research and scoring, competitor keyword analysis, metadata optimization, A/B test planning, launch checklist
trailofbits/skills
Constant-time testing detects timing side channels in cryptographic code. Use when auditing crypto implementations for timing vulnerabilities.
dotnet/skills
Analyzes test suites in any language and tags each test with standardized traits (positive, negative, critical-path, boundary, smoke, regression, integration, performance, security). Use when the user wants to categorize, audit, or label tests with traits. Works across .NET (MSTest/xUnit/NUnit/TUnit), Python (pytest), TS/JS (Jest/Vitest), Java, Go, Ruby, Rust, Swift, Kotlin, PowerShell, and C++ — auto-editing when the framework has canonical tag syntax, otherwise report-only. Do not use for writ
yonatangross/orchestkit
Grade work that already exists and decide whether it can merge. Runs the project's current unit, integration, and E2E suites plus security scanning and type checking, scores every dimension 0-10, and returns a merge verdict with a VERIFIED-vs-CLAIMED evidence manifest. Writes no test files and edits no source. Use when verifying changes are ready to merge. Use /ork:cover instead when the tests still have to be written.