Skip to main content
⚡ OpenDevDocs
Fundamentals
fundamentalsdebuggingGuideBeginner

Debugging Fundamentals

Systematic troubleshooting: reproducing bugs, reading stack traces, bisecting errors, browser devtools, and scientific debugging methodologies.

Verified: 2026-09-30
Platforms:
all
#debugging#devtools#stack-trace#troubleshooting#fundamentals

Debugging Fundamentals

Debugging is the methodical process of identifying, isolating, and fixing defects or bugs in software. Great engineers are distinguished not by never making mistakes, but by their ability to systematically diagnose and resolve complex errors quickly.


1. The 5-Step Scientific Debugging Method

[ 1. Reproduce ] ──► [ 2. Read Trace ] ──► [ 3. Isolate ] ──► [ 4. Hypothesize & Fix ] ──► [ 5. Prevent ]
  1. Consistently Reproduce: Create a minimal set of deterministic steps that trigger the bug every single time.
  2. Read the Full Stack Trace: Read from top to bottom. Find the exact file name and line number where the exception was thrown.
  3. Isolate the Variable / Boundary: Strip away unrelated components, network requests, or state. Use binary search (commenting out half the code or using git bisect) to pinpoint the offending line.
  4. Hypothesize and Test Fix: Formulate a clear hypothesis ("Variable X is undefined because async fetch hasn't resolved yet"). Apply the smallest targeted fix and verify.
  5. Prevent Regression: Write an automated test covering the failure case so the bug can never reoccur unnoticed.

2. Reading a Stack Trace Effectively

Consider this Node.js runtime exception:

TypeError: Cannot read properties of undefined (reading 'toUpperCase')
    at formatUsername (/app/src/utils/user.ts:14:23)
    at renderUserProfile (/app/src/components/Profile.tsx:42:12)
    at async UsersPage (/app/src/app/users/page.tsx:8:19)

How to analyze this trace:

  • Error Type: TypeError — attempting an operation on an incompatible type.
  • Root Cause: An object or variable was undefined, and code tried to call .toUpperCase() on it.
  • Trigger Line: Look at the top application file: /app/src/utils/user.ts at line 14, column 23.
  • Caller Chain: formatUsername was called by renderUserProfile on line 42, which was called by UsersPage on line 8.

3. Essential Debugging Tools

1. Browser Developer Tools (F12 / Cmd+Opt+I)

  • Console: Inspect logs, warnings, errors, and evaluate live JavaScript expressions.
  • Network Tab: Inspect HTTP status codes, request headers, payload bodies, timing waterfalls, and response sizes.
  • Sources / Debugger: Set conditional breakpoints, step into functions (F11), step over (F10), and inspect the call stack and local scope variables.

2. VS Code Integrated Debugger

Configure .vscode/launch.json to attach breakpoints directly to Next.js or Node.js processes without littering code with console.log:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "pnpm dev"
    }
  ]
}

4. Common Debugging Anti-Patterns

Anti-PatternWhy it failsBetter Approach
"Shotgun Debugging"Changing random lines of code hoping the error goes away.Stop, read the error message carefully, and trace data flow step-by-step.
Swallowing Errors with Empty catchHides the root cause, making failures silent and unpredictable.Always log or re-throw caught exceptions: catch (err) { console.error(err); }.
Leaving Temporary console.log in ProductionClutters production logs and can leak sensitive user PII.Use structured loggers (Pino, Winston) with configurable log levels (debug, info, error).

On this page