Langsung ke konten
Skillpedia
Testing107k Β· #768

debugging-and-error-recovery

Fungsinya

Panduan ini membantu Anda menemukan dan memperbaiki error pada kode secara sistematis. Panduan ini mengajarkan Anda untuk berhenti, menyelidiki, dan menyelesaikan masalah, bukan menebak-nebak.

Kapan dipakai

  • βœ“Saat sebuah tes gagal setelah ada perubahan.
  • βœ“Saat program tidak berjalan sebagaimana mestinya.
  • βœ“Saat menemukan error yang tidak terduga.

Link skill

https://github.com/addyosmani/agent-skills/blob/main/skills/debugging-and-error-recovery/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/addyosmani/agent-skills/blob/main/skills/debugging-and-error-recovery/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œKode saya memunculkan error aneh saat mencoba menyimpan data pengguna, bisakah Anda bantu cari tahu penyebabnya?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Caranya adalah dengan meminta Anda mereproduksi error tersebut, lalu menemukan di mana error itu terjadi, menyederhanakan masalahnya, dan akhirnya memperbaiki penyebab utamanya.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Debugging and Error Recovery

Overview

Systematic debugging with structured triage. When something breaks, stop adding features, preserve evidence, and follow a structured process to find and fix the root cause. Guessing wastes time. The triage checklist works for test failures, build errors, runtime bugs, and production incidents.

When to Use

  • Tests fail after a code change
  • The build breaks
  • Runtime behavior doesn't match expectations
  • A bug report arrives
  • An error appears in logs or console
  • Something worked before and stopped working

The Stop-the-Line Rule

When anything unexpected happens:

1. STOP adding features or making changes
2. PRESERVE evidence (error output, logs, repro steps)
3. DIAGNOSE using the triage checklist
4. FIX the root cause
5. GUARD against recurrence
6. RESUME only after verification passes

Don't push past a failing test or broken build to work on the next feature. Errors compound. A bug in Step 3 that goes unfixed makes Steps 4-6 wrong.

The Triage Checklist

Work through these steps in order. Do not skip steps.

Step 1: Reproduce

Make the failure happen reliably. If you can't reproduce it, you can't fix it with confidence.

Can you reproduce the failure?
β”œβ”€β”€ YES β†’ Proceed to Step 2
└── NO
    β”œβ”€β”€ Gather more context (logs, environment details)
    β”œβ”€β”€ Try reproducing in a minimal environment
    └── If truly non-reproducible, document conditions and monitor

When a bug is non-reproducible:

Cannot reproduce on demand:
β”œβ”€β”€ Timing-dependent?
β”‚   β”œβ”€β”€ Add timestamps to logs around the suspected area
β”‚   β”œβ”€β”€ Try with artificial delays (setTimeout, sleep) to widen race windows
β”‚   └── Run under load or concurrency to increase collision probability
β”œβ”€β”€ Environment-dependent?
β”‚   β”œβ”€β”€ Compare Node/browser versions, OS, environment variables
β”‚   β”œβ”€β”€ Check for differences in data (empty vs populated database)
β”‚   └── Try reproducing in CI where the environment is clean
β”œβ”€β”€ State-dependent?
β”‚   β”œβ”€β”€ Check for leaked state between tests or requests
β”‚   β”œβ”€β”€ Look for global variables, singletons, or shared caches
β”‚   └── Run the failing scenario in isolation vs after other operations
└── Truly random?
    β”œβ”€β”€ Add defensive logging at the suspected location
    β”œβ”€β”€ Set up an alert for the specific error signature
    └── Document the conditions observed and revisit when it recurs

For test failures (npm shown β€” substitute the repository's own test command, per the test-driven-development skill's Discover the Stack First section):

# Run the specific failing test
npm test -- --grep "test name"

# Run with verbose output
npm test -- --verbose

# Run in isolation (rules out test pollution)
npm test -- --testPathPattern="specific-file" --runInBand

Step 2: Localize

Narrow down WHERE the failure happens:

Which layer is failing?
β”œβ”€β”€ UI/Frontend     β†’ Check console, DOM, network tab
β”œβ”€β”€ API/Backend     β†’ Check server logs, request/response
β”œβ”€β”€ Database        β†’ Check queries, schema, data integrity
β”œβ”€β”€ Build tooling   β†’ Check config, dependencies, environment
β”œβ”€β”€ External service β†’ Check connectivity, API changes, rate limits
└── Test itself     β†’ Check if the test is correct (false negative)

Use bisection for regression bugs:

# Find which commit introduced the bug
git bisect start
git bisect bad                    # Current commit is broken
git bisect good <known-good-sha> # This commit worked
# Git will checkout midpoint commits; run your test at each
git bisect run npm test -- --grep "failing test"  # substitute the repository's focused-test command

Step 3: Reduce

Create the minimal failing case:

  • Remove unrelated code/config until only the bug remains
  • Simplify the input to the smallest example that triggers the failure
  • Strip the test to the bare minimum that reproduces the issue

A minimal reproduction makes the root cause obvious and prevents fixing symptoms instead of causes.

Step 4: Fix the Root Cause

Fix the underlying issue, not the symptom:

Symptom: "The user list shows duplicate entries"

Symptom fix (bad):
  β†’ Deduplicate in the UI component: [...new Set(users)]

Root cause fix (good):
  β†’ The API endpoint has a JOIN that produces duplicates
  β†’ Fix the query, add a DISTINCT, or fix the data model

Ask: "Why does this happen?" until you reach the actual cause, not just where it manifests.

Step 5: Guard Against Recurrence

…

Pertanyaan umum

Apa maksud 'preserve evidence'?

Maksudnya adalah menyimpan informasi penting tentang error, seperti pesan error, log, atau langkah-langkah yang Anda lakukan hingga error itu muncul.

Mengapa saya tidak boleh menambah fitur baru saat ada yang rusak?

Karena menambah kode bisa memperparah masalah atau menyembunyikan penyebab aslinya, sehingga lebih sulit diperbaiki.

Apa itu 'bisection'?

Itu adalah teknik untuk mencari perubahan spesifik yang menyebabkan masalah, dengan menguji versi kode yang lebih lama satu per satu hingga menemukan versi yang berfungsi dengan baik.

Detail

Deskripsi asli dari pembuat

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why β€” a systematic approach to finding and fixing the root cause rather than guessing.

repo: addyosmani/agent-skills

Popularitas

Bintang GitHub
107k
Peringkat
#768
Lisensi
MIT
Diperbarui
13/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa