The traceback names a line, and that line is usually not where the mistake is. Fixing programming mistakes is a reading skill before it is a writing skill: reproduce the failure, shrink it, and only then change code. Most wasted debugging hours go into editing before any of those three steps has happened.
Read the whole message
Error messages are written for the person who wrote the library, so they are dense, but they are rarely dishonest. Read the last line first, then walk upward to the first line that belongs to your own file. The exception type tells you what went wrong: a missing key, a wrong type, an index past the end of a list.
If the message mentions a name you do not recognise, look that name up before touching your logic. Half of all confusing failures are a function being called with the wrong shape of data.
Reproduce, then shrink
A bug you can trigger with one command is halfway fixed. Write the smallest sequence of inputs that produces it and keep that sequence in a scratch file. If it only appears sometimes, the difference is usually ordering, timing, or state left behind by an earlier run.
Delete half the code. If the bug survives, delete half of what remains. This feels wasteful and takes minutes; guessing takes hours. A five-line reproduction is also the fastest way to get help from another person, because nobody can debug a screenshot of a sixty-line file.
Where the fix usually hides
- A value that is empty when you assumed it was filled.
- A loop that runs one time too many, or never starts at all.
- One variable reused for two different meanings.
- A file path that works from your folder and nowhere else.
- A change made in one place while a copy of it still lives in another.
Check each of these against your reproduction before you edit anything. Guessing produces a second bug stacked on the first.
Fix, then prove it
Change one thing at a time, and run the reproduction after every change. When it passes, remove your debug prints and run the original scenario again, because fixing the small case can break the large one. If the same bug has now appeared twice, write a check that fails on the old behaviour before moving on.
When to ask for help
Ask after twenty minutes of genuine shrinking, not after two minutes of frustration. Bring the reproduction, the exact message, what you expected, and what you have already ruled out. That note usually shows you the answer while you are typing it.
Most mistakes are not stupid; they are ordinary assumptions that stopped being true. The habit worth building is the loop itself — reproduce, shrink, change one thing, verify — because it works on every language you will ever touch.