---
title: "Debugging 101: for vibe coding in production · Arpit Solanki"
description: "How to think when things break. A first-principles way to debug any stack, and how to use Cursor and Claude Code for it without switching your brain off."
url: https://arpitsolanki.in/blog/debugging-101.html
---

Canonical page: https://arpitsolanki.in/blog/debugging-101.html

[← all posts](https://arpitsolanki.in/blog.html)

# Debugging 101: for vibe coding in production

26 jun 2026 · ~20 min · first posted on [Medium](https://medium.com/@Arpit_Solanki/debugging-101-for-vibe-coding-in-production-82837b76d1c6)

![Debugging 101](https://arpitsolanki.in/blog/img/debugging-1.jpg)

### Debugging From First Principles:

You will learn a lot of technologies. React, Node, Python, databases, cloud, whatever is hot this year. But there is one skill that i see everyone struggles with. That is debugging. Everyone is just staring at the error and pasting it into ChatGPT hoping for a miracle is going to hit a wall eventually.

This blog will teach you how to think when things break. We will use examples from React, Python, Node and other tools, but the framework is universal. It works for any language, any framework, any system. And yes, we will also discuss about how to use AI tools like Cursor and Claude Code for debugging, because they are genuinely useful, but only if you know how to use them properly.

## 1. How to understand your vibe coded billion dollar B2b SaaS

Most people build something (or vibe code something with AI), it works, they move on. They never really understand what is happening under the hood. Then when it breaks, they have no mental model to reason about.

Before you can debug anything, you need to understand what is supposed to happen. Not vaguely, not "the button sends data to the backend." You need to know the exact flow.

Let me give you an example. Say you have a simple full stack app. A React frontend, a Node/Express backend, and a PostgreSQL database. When a user clicks "Submit" on a form, here is what should happen:

a. The React component captures the form data and puts it into a state variable. b. An onClick handler fires, which calls a function that makes a fetch() or axios.post() request to your backend API endpoint (say, POST /api/users). c. This request travels over the network (HTTP) to your server. d. Express receives the request, the route handler runs, it validates the data. e. The handler calls a database query (say, INSERT INTO users…) using your ORM or raw SQL. f. PostgreSQL executes the query and returns a result. g. The Express handler sends a JSON response back. h. The React frontend receives the response and updates the UI (shows a success message, redirects, whatever).

That is 8 steps. A bug can happen at any single one of these steps. If you do not know these steps exist, you are just guessing. You are randomly adding console.log statements hoping to stumble onto the problem. That is gambling.

Exercise for you: Pick any feature in a project you have built. Write down every single step that happens from the moment the user does something to the moment they see the result. Include the network, the server, the database, everything. If you fail at this, you do not understand billion dollar b2b SaaS well enough 🙂.

## 2. You will notice: Every Bug is a Gap Between What You Expected and What Actually Happened

This sounds obvious but it is the foundation of all debugging.

Your code does not "not work." That is not a useful statement. What is actually happening is: you expected behavior X, but you are getting behavior Y. The bug lives in the gap between X and Y.

So the first thing you do when something breaks is ask yourself two very specific questions:

a. What did I expect to happen? b. What actually happened?

Be precise. Not "the page is broken." Instead: "I expected the user list to render with 5 items after the API call, but instead I see a blank screen and there is an error in the console that says 'Cannot read properties of undefined (reading map).'"

That second version already tells you a lot. Something is undefined that you expected to be an array. Now you have a direction to investigate.

## 3. Read the Error Message (No, Actually Read It)

I know this sounds insulting. But I have seen people (including experienced developers) see a red error in the console, panic, and immediately paste it into an AI tool without reading a single word of it.

Error messages are written by developers for developers. They are trying to tell you what went wrong. Most of the time, they are surprisingly specific.

Let me show you some real examples.

a. A React error

```
TypeError: Cannot read properties of undefined (reading 'map')
 at UserList (UserList.jsx:12:25)
```

What is this telling you?

First, it is a TypeError. Something is the wrong type. Second, it says "undefined." Something you thought had a value is actually undefined. Third, you are calling .map() on it, which means you expected an array. Fourth, it tells you the exact file (UserList.jsx) and the exact line (line 12, column 25).

So your debugging path is clear. Go to UserList.jsx, line 12. Find what you are calling .map() on. Figure out why that thing is undefined. Maybe the API has not returned data yet (the component rendered before the fetch completed). Maybe the API returned an object instead of an array. Maybe you have a typo in the variable name.

b. A Python backend error

```
Traceback (most recent call last):
 File "app.py", line 45, in create_user
 db.session.add(user)
 File "/lib/sqlalchemy/orm/session.py", line 1890, in add
 raise UnmappedInstanceError(instance)
 sqlalchemy.orm.exc.UnmappedInstanceError: Class 'dict' is not mapped
```

Read it from bottom to top (Python tracebacks show the most recent call last, so the actual error is at the bottom). It says: you are trying to add a dict to the database session, but SQLAlchemy expects a mapped model instance. So somewhere in your create_user function on line 45, you are passing a plain dictionary instead of a User() object. The fix is clear: create a User model instance from the dictionary first.

c. A Node.js error

```
Error: connect ECONNREFUSED 127.0.0.1:5432
 at TCPConnectWrap.afterConnect
```

This one is even simpler. Your application tried to connect to port 5432 (that is PostgreSQL's default port) on localhost, and the connection was refused. Meaning PostgreSQL is not running on your machine. The fix is: start your database server.

The point is not that these are hard errors. The point is that if you actually read them carefully, they point you directly to the problem. The habit of reading error messages carefully will save you more time than any tool ever will.

## 4. Form a Hypothesis Before You Touch Anything

After you have read the error and understood the gap between expected and actual behavior, you need to think. Not Google. Not paste into AI. Think.

Ask yourself: given what I know about how this system works (from step 1) and what the error is telling me (from step 3), what are the possible causes?

Let me walk you through this with a real scenario.

Scenario: Your API endpoint POST /api/orders is returning a 500 Internal Server Error. It was working yesterday. You did not change the orders code, but you deployed a new version of the app this morning.

Here is how you reason about it:

a. The 500 means the server is crashing or throwing an unhandled error somewhere in the request handler.

b. It was working yesterday, so the fundamental logic is probably fine. Something changed.

c. You deployed this morning. What was in that deployment? Maybe a new dependency version. Maybe a change to the database schema. Maybe an environment variable that is different in production.

d. So your hypotheses might be: Hypothesis 1: A new dependency broke something in the orders flow. Hypothesis 2: The database schema changed and the orders query is now failing. Hypothesis 3: An environment variable (like a Stripe API key or database URL) is missing or wrong in production.

Now you have three specific things to check. You are not randomly searching. You are systematically testing theories. like a doctor works. Patient comes in with a headache. The doctor does not randomly prescribe medicines. They ask questions (when did it start, where does it hurt, did anything change recently), form hypotheses (tension, migraine, dehydration, something more serious), and run tests to narrow it down.

## 5. Isolate the Problem (Shrink the Search Space)

You have your hypotheses. Now you need to figure out which one is correct. The way you do this is by isolating. You remove variables until you find the one that matters.

### The simplest isolation technique: check if the problem is in the frontend or the backend.

Open your browser's Network tab (in Chrome DevTools, press F12 and go to the Network tab). Make the request that is failing. Look at the actual HTTP request and response.

If the request is not even being sent, the problem is in your frontend code (maybe the button's onClick is not wired up, or you are hitting the wrong URL).

If the request is being sent but the response is a 500, the problem is in your backend. Now you have cut your search space in half.

If the request is being sent, the response is 200, and the data looks correct, but the UI is still broken, the problem is in how your frontend is handling the response.

### Add targeted logging at the boundaries.

Boundaries are the points where data moves from one part of the system to another. These are the most common places where things break.

For example, in your Express route handler:

```
app.post('/api/orders', async (req, res) => {
 console.log('1. Request received, body:', JSON.stringify(req.body));

 const validated = validateOrder(req.body);
 console.log('2. After validation:', JSON.stringify(validated));

 const result = await db.query('INSERT INTO orders …', [validated.item, validated.qty]);
 console.log('3. DB result:', JSON.stringify(result));

 res.json({ success: true, order: result });
});
```

Now run the failing request and check your logs. If you see log 1 but not log 2, the crash is happening in validateOrder(). If you see log 2 but not log 3, the crash is in the database query. You have pinpointed the exact function that is failing.

This is not "just adding console.log." This is strategic placement of checkpoints at system boundaries to narrow down exactly where the data flow breaks.

### The binary search method for larger problems.

If you have a big function or a long chain of operations, you do not need to check every single line. Put a log in the middle. If the log prints, the bug is in the second half. If it does not print, the bug is in the first half. Put another log in the middle of that half. Repeat. You will find the exact line in log(n) steps instead of n steps.

This is literally binary search applied to debugging. It works shockingly well. I have mostly read it in blogs, never used it though 🙂

## 6. Common Bug Categories and How to Think About Each One

Not all bugs are the same. Once you have been debugging for a while, you start recognizing patterns. Here are the big categories and the mental framework for each.

### "It works on my machine but not in production."

This is almost always an environment problem. The things to check: Are all environment variables set correctly in production? Is the database URL pointing to the production database (not your local one)? Are there files or paths that exist on your machine but not on the server? Is there a version mismatch (Node 18 locally, Node 16 on the server)? Is there a CORS issue that does not show up in local development?

The systematic approach: diff your local environment with your production environment. Compare .env files, Node/Python versions, installed packages, and OS differences.

### "It worked yesterday but not today."

Something changed. Your job is to find what. Check the git log. What commits were made since it last worked? Check if any dependencies were updated (look at your lockfile changes). Check if the database schema changed (new migration?). Check if any external service you depend on (a third party API, a payment gateway) is down or changed their API.

Pro tip: git bisect is an incredible tool for this. It does a binary search through your git history to find the exact commit that broke things. If you have 100 commits between "working" and "broken," git bisect will find the guilty commit in about 7 steps.

### "It works sometimes and fails sometimes."

These are the hardest bugs. Intermittent failures usually come from: Race conditions (two things happening at the same time and stepping on each other). Timing issues (a network request takes longer than expected sometimes). Resource exhaustion (the server runs out of memory or connections after a while). Caching (stale data from a cache mixing with fresh data).

The approach: look for anything that involves timing, shared resources, or parallel operations. Try to find the pattern. Does it fail under load? Does it fail after a certain number of requests? Does it fail only for certain users? The pattern will lead you to the cause.

### "There is no error, but the output is wrong."

These are logic bugs. The code runs fine, it just does the wrong thing. No stack trace to help you here.

The approach: trace the data manually. Start with the input. What is the raw data going in? Then follow it through every transformation. At which point does the data stop being what you expect?

A common example: you have a price calculation that is off by a few cents. You trace it and find that you are doing floating point math (0.1 + 0.2 = 0.30000000000000004 in JavaScript). The code is not crashing, it is just doing math wrong. You would never find this by adding a debugger breakpoint. You find it by tracing the data and comparing expected vs actual at each step.

## 7. Debugging with AI Tools (Cursor, Claude Code, and Others)

Let us be real. AI tools have changed how we debug. Cursor, Claude Code, ChatGPT, GitHub Copilot, all of these can look at your code, read an error message, and often suggest the right fix. You should absolutely use them. But you should use them intelligently, not blindly.

a. When AI debugging works really well.

AI tools are great for pattern matching. If you have a common error that thousands of developers have hit before, AI has seen it in its training data and can tell you the fix instantly.

Examples where AI shines: You forgot to await an async function. You have a missing import or a typo in a variable name. You are using a library API incorrectly (wrong argument type, deprecated method). You have a common configuration error (CORS headers, webpack config, tsconfig). You get a cryptic error from a framework and you do not know what it means.

For these kinds of bugs, paste the error and relevant code into Claude Code or Cursor's chat, and it will probably give you the answer in seconds. No shame in that. It is genuinely faster.

In Cursor specifically, you can select the broken code, press Cmd+K (or Ctrl+K), and describe the issue. Or use the chat panel to paste the error with context. Cursor has the advantage of seeing your whole codebase, so it can understand how different files relate to each other. There are bugbots in cursor so that you don't have to do it manually. You can also use code reviews in cursor or things like coderabbit.

In Claude Code (the terminal tool), you can just say "I am getting this error when I run npm start" and paste the error. It can read your project files, look at your package.json, check your configurations, and often pinpoint the issue because it understands the full project structure.

### When AI debugging does not work well.

AI tools struggle with:

- Bugs that require understanding your specific business logic. If the bug is "users are being charged twice" and the logic spans 5 services and 3 databases, the AI does not understand your business rules well enough to trace through all of that.
- Bugs that involve system level behavior. Things like connection pooling exhaustion, memory leaks over time, thread deadlocks, DNS resolution failures. These require understanding how the operating system, the runtime, and the network interact. AI tools often give generic advice here.
- Intermittent bugs with no clear reproduction steps. If you cannot show the AI the error consistently, it is guessing just like you are.

### The right way to use AI for debugging.

Do not just paste an error and say "fix this." That is the debugging equivalent of going to a doctor and saying "I feel bad, fix me." Give context.

A good prompt for debugging looks like this:

"I have a Node.js Express API with a PostgreSQL database. When I hit POST /api/users with a valid JSON body, I get a 500 error. Here is the route handler code: \[paste code\]. Here is the error from the server logs: \[paste error\]. The database is running and I can connect to it from psql directly. This was working until I upgraded the pg library from version 8.7 to 8.12."

That prompt gives the AI everything it needs: the stack, the code, the error, what you have already checked, and what changed recently. It can now give you a precise answer instead of a generic one.

### using AI to fix without understanding.

Here is what happens to a lot of people. They get an error, paste it into Claude or Cursor, get a fix, apply it, and move on. It works. Great. Until a similar bug shows up a week later and they have no idea how to even start thinking about it because they never understood the first fix.

Every time AI gives you a fix, take 2 minutes to understand why it worked. What was the actual problem? Why did the fix solve it? What could you have done to find this yourself?

## 8. The Art of Reading Stack Traces (might seem complex but it's the best way)

A stack trace is the single most useful piece of information you get when something crashes. It tells you exactly what sequence of function calls led to the crash. But most beginners see a wall of text and panic.

Here is how to read one properly.

a. The structure of a stack trace.

A stack trace is a list of function calls, ordered from the most recent call (where the crash happened) to the oldest call (where the program started). Think of it like a call chain: function A called function B, which called function C, and C crashed.

In most languages, the actual error is either at the top (JavaScript, Java) or at the bottom (Python). The line that says "Error:" or "Exception:" is your starting point.

b. Your code vs library code.

A stack trace will include frames from your code AND frames from third party libraries or the language runtime. You almost always want to focus on YOUR code first. The bug is rarely in Express or React or Django itself. It is in how you are using them.

Scan the stack trace for file paths that belong to your project (like /src/controllers/userController.js) and skip the ones that are inside node_modules or site-packages. The frame from your code that is closest to the error is usually where the bug is. well, well, well, i have never done this and claude told me about this shit

c. A practical example.

Here is a Node.js stack trace:

```
TypeError: Cannot read properties of null (reading 'email')
 at formatUser (/src/utils/format.js:15:22)
 at processUsers (/src/services/userService.js:42:18)
 at async handler (/src/routes/users.js:28:20)
 at Layer.handle [as handle_request] (node_modules/express/lib/router/layer.js:95:5)
 at next (node_modules/express/lib/router/route.js:144:13)
```

Reading this: The error is TypeError: something is null and you tried to access .email on it. It happened in formatUser in format.js at line 15. formatUser was called by processUsers in userService.js at line 42. processUsers was called by the route handler in users.js at line 28. The rest is Express internals. Ignore it.

So go to format.js line 15. You are probably doing something like user.email where user is null. Why is user null? Go up one level to userService.js line 42. What is being passed to formatUser? Maybe the array of users from the database has a null entry. Now you check your database query. You find the issue.

See how the stack trace literally hands you the trail? I feel like a detective while doing this 😂. this is the fun part of coding now for me

## 9. Debugging Network Issues (Frontend to Backend Communication)

A huge category of bugs that beginners struggle with is "my frontend is not talking to my backend properly." This is because there are so many things that can go wrong between a browser and a server. Let me break this down.

a. Use the browser's Network tab. This always helps bro.

Whenever you have a frontend issue related to data or API calls, the very first thing you open is Chrome DevTools, Network tab. Every single HTTP request your app makes shows up here. You can see: The URL that was requested (is it correct?). The HTTP method (is it POST when it should be POST?). The request headers (is the Authorization header present?). The request body (is the data you are sending correct?). The response status code (200, 400, 404, 500?). The response body (what did the server actually send back?). The timing (how long did it take?).

I think this answers 80% of frontend to backend debugging questions.

### Common network issues and their status codes.

**400 Bad Request**: Your frontend is sending data in the wrong format. The server received the request but rejected it because the data is invalid. Check your request body.

**401 Unauthorized:** You are not sending an authentication token, or the token is expired/invalid. Check your Authorization header.

**403 Forbidden:** You are authenticated but not allowed to access this resource. This is a permissions issue, not an auth issue.

**404 Not Found:** The URL is wrong. You are requesting /api/user but the server has /api/users (notice the missing 's'). Or the server is not running. Or you are hitting the wrong port.

**500 Internal Server Error:** The server crashed while processing your request. The bug is in the backend code. Check the server logs.

### CORS Error

(shows up in console, not as a status code): Your frontend and backend are on different origins (like localhost:3000 and localhost:8080) and the backend is not configured to allow cross origin requests. The fix is on the server side: add CORS headers. ***I think this is the most common error among all that you'll face.***

### The "is it the frontend or the backend" test.

Simple, Use curl or Postman to make the same API request directly, bypassing your frontend entirely. If the request works from curl but not from your React app, the problem is in your frontend code (wrong URL, missing headers, wrong data format). If it also fails from curl, the problem is in the backend.

This simple test eliminates an entire half of your system from the investigation.

## 10. Environment and Configuration Bugs

These are boring but incredibly common. Your code is perfectly correct, but it does not work because something in the environment is wrong.

a. The ".env file that does not exist" bug.

You have a .env file locally with DATABASE_URL=postgres://localhost:5432/mydb You deploy to production. There is no .env file on the server (because .env is in .gitignore, as it should be). Your app crashes because process.env.DATABASE_URL is undefined.

The fix: make sure all environment variables are set in your hosting platform (Render, Railway, Vercel, AWS, whatever). The real lesson: always check for undefined environment variables at app startup and crash early with a clear error message, instead of failing mysteriously later when you try to use them. I would say, use a password manager -> [Things you must secure before deploying a backend to production](https://medium.com/@shivambhadani_/things-you-must-secure-before-deploying-a-backend-to-production-1eeb641cdf4b). Read this blog to learn this.

### The "wrong database" bug.

Your app is running, but the data looks wrong. You add a user and it does not show up. may be your production app is still pointing to your development database (or vice versa).

### The "it works in dev but not in production" checklist.

mostly i have seen these reasons so frequently:

Compare Node/Python/whatever version. Compare all environment variables. Check if the build step is different (maybe your prod build is minifying code and breaking something). Check if the server has access to external services (maybe your production server cannot reach the database because of a firewall rule).

## 11. A Complete Debugging Walkthrough

Let's put all of this together with a start to finish example.

The situation: You are building a todo app. React frontend, Express backend, PostgreSQL database. The user types a todo, clicks "Add," and nothing happens. No error on screen. The todo just does not appear in the list.

Here is how you debug it, step by step.

### What did I expect?

When the user clicks "Add," the todo should appear in the list below. What actually happened? The click happens (the button visually responds), but the list does not update.

Open Chrome DevTools, Network tab. Click "Add" again and watch.

Scenario 1: No network request appears. The problem is in the frontend. The onClick handler is not making an API call. Check your React code. Maybe you forgot to call the API function, or maybe there is an early return before the fetch.

Scenario 2: A POST request appears but it shows status 400. Click on the request, look at the request body. Is the data in the right format? Maybe the server expects { "title": "Buy milk" } but you are sending { "todo": "Buy milk" }. Fix your frontend to send the right field name.

Scenario 3: A POST request appears, status 201 (success), and the response contains the new todo. So the backend is fine. The problem is that the frontend is not updating after the successful POST. Check your React code: after the API call, are you re fetching the list? Or adding the new item to state? Maybe you forgot to call setTodos(\[...todos, newTodo\]) after the API responds.

Scenario 4: A POST request appears, status 500. The backend is crashing. Check the server terminal/logs for the error. Read the stack trace. Maybe the database query has a typo in the column name. Maybe the database table does not exist yet because you forgot to run migrations.

See how each step narrows down the problem? You did not touch a single line of code until you understood where the bug was. That is first principles debugging.

Now go break something and fix it. That is how you learn.
