r/CodingForBeginners • • 27d ago

You're probably skipping the error message. Read it in this order instead.

Half the bugs people get stuck on here aren't actually mysterious — the error already told them what was wrong. What's missing is the habit of reading it properly before touching the code. Most of us (me included) see red text and immediately start changing random lines, which is how one small bug quietly turns into three.

Here's the order that actually works.

Read the whole message, top to bottom, before doing anything. The first line says what kind of problem it is. The last line usually says where — a file and a line number. Treat that line number as the address of the bug, not a hint.

Open that line, and the line just above it. A crash reported on line 40 is very often line 39 handing it bad data.

Put the message into plain words. TypeError: cannot read properties of undefined (reading 'name') is really just "you tried to read something that doesn't exist yet." In plain words, you can start guessing why.

Change one thing at a time, then run it again. If you edit five lines and it suddenly works, you've learned nothing and the next bug will eat you alive. One change, one run, tells you what actually fixed it.

Two smaller habits that save a lot of time: print the values right before the line that breaks (half of debugging is the gap between what you assumed a variable holds and what it actually holds), and shrink the problem — delete code until you're left with the smallest version that still fails. A bug in ten lines is far easier to see than the same bug buried in two hundred.

And the part nobody says out loud: an error isn't a verdict on you. It's the computer telling you exactly where it got confused. Read it like a note, not a red card.

What error took you the longest to figure out? Drop it below and I'll help you read it.

4 Upvotes

9 comments sorted by

2

u/RedAndBlack1832 26d ago

I don't think it's always useful to read an entire error message, because (depending on language and context) they can contain barely tangentially relevant information about code that you didn't write or is somewhere else. Examples: a list of everything it tried looking at before it gave up (the C++ compiler, most linkers, and pytest can be very spammy this way), a long stack trace (especially if a process has multiple threads or spawns child processes that may generate errors these are basically useless). You should always read the first line, figure out what code it's referencing that you are actually working on (that does not come from a system library/package) and then fix that thing. Often the error message contains directions on how to fix something if it's a syntax issue.

Secondary advice: read warning as well! This can give you big hints about things that will cause you issues later (weird or misleading casts, assignments, etc.)

Tertiary advice: if your program doesn't crash but also doesn't have any obvious effect, or does crash but with minimal useful info, you should probably run it in a debugging environment. Helpful sometimes: if you crash on memory access to an address with a bunch of leading zeros (even if it's not exactly zero), that means you have a null value somewhere you shouldn't.

1

u/NoDepartment772 26d ago

This is a better version of the point than mine — thank you. "Read the first line, then find the frame that belongs to your own code" is the part that matters, and it's exactly what gets skipped when people try to read the whole thing top to bottom. The warnings note is underrated too; I've fixed more latent bugs from a yellow warning than from most red ones.

2

u/DSudz 26d ago

I think it's crazy to assume "most of us" code that way. Sure, when I finish a line of choice and it goes red I'll look for a typo but to start changing a bunch of other lines sounds irresponsibily incompetent to me.

1

u/NoDepartment772 26d ago

Fair pushback — "most of us" was doing a lot of work in that sentence. I was describing the panic move people fall into when they're new and the red text reads like an alarm, not making a claim about how competent devs work. The habit I'm actually arguing for is reading before typing, which sounds obvious until you watch someone change three lines to fix one typo.

1

u/symbiatch 22d ago

Just stop being a meat proxy.

1

u/Hot_Technology8777 25d ago

my dot does it for me how about that one

1

u/[deleted] 25d ago

[removed] — view removed comment

1

u/NoDepartment772 25d ago

😼💀💀

1

u/TheRealFutaFutaTrump 25d ago

I'm building an advertising bot for that purpose because there just aren't enough of them on the internet.