
The short answer
Read an error message in this order: what went wrong (the message), where (the file and line number), and how you got there (the stack trace, read from the top until you reach your own code). Then change one thing, run again, and read the new message. Most bugs are found in minutes this way.

Errors are not the computer shouting at you. They are the computer telling you exactly where it got confused. Treat every error as a clue.
Why beginners struggle with errors
An error message looks like a wall of scary text, so the natural reaction is to panic, scroll past it, and start changing random things. That makes debugging slow and frustrating.
Developers are not smarter at this; they have a habit. They slow down and read the error like a note left for them.
The three parts of almost every error
Here is a typical PHP error from a Laravel app:
ErrorException: Undefined variable $total in /var/www/app/Http/Controllers/OrderController.php:42
| Part | Here | What it tells you |
|---|---|---|
| Type | ErrorException |
The kind of problem |
| Message | Undefined variable $total |
What went wrong, in plain-ish words |
| Location | OrderController.php:42 |
The file and line where it was noticed |
So this says: "On line 42 of OrderController.php, you used a variable called $total that was never given a value." Open that file, go to line 42, and look for where $total should have been set. Often it is a typo ($totl) or it is set inside an if that did not run.
Reading a stack trace
Sometimes the error happens deep inside a library, not in your code. The stack trace is the list of steps (function calls) that led there, like footprints. Here is a JavaScript example from a browser console:
TypeError: Cannot read properties of undefined (reading 'name')
at showUser (app.js:12:24)
at loadPage (app.js:30:5)
at main.js:4:1
Read it like this:
- Top line: the type and message. "You tried to read
namefrom something that isundefined", meaning a value that does not exist yet. - Next lines: where it happened, most recent first. It broke in
showUser, on line 12, column 24 ofapp.js. - Further down: how you got there.
showUserwas called byloadPage, which was called frommain.js.
The rule: read from the top down, and stop at the first line that is in your own code. Lines inside frameworks or libraries are usually not where the bug is; they are where the bad value finally caused trouble.
showUser was called with no user, perhaps because the data had not loaded yet. Line 30 (loadPage) is where to check what was passed in.Common error types and what they usually mean
| Error says | Usually means | First thing to check |
|---|---|---|
undefined, null, Undefined variable |
A value you expected does not exist | Where the value should have been set |
syntax error, unexpected ... |
A typo in the code's grammar | The line shown and the line just above: a missing ;, ) or } |
not found, does not exist, No such file |
A name or path is wrong | Spelling, capital letters, the folder you are in |
Permission denied |
The user running the code may not access a file | File permissions (see Linux files and permissions) |
Connection refused, could not connect |
A service is not running or the address is wrong | Is the database or server running? Is the host and port right? |
Status code 404 |
No page or route matched | The URL and your routes |
Status code 500 |
The server's code crashed | The server's error log for the real message |
Status code 419 (Laravel) |
The form's security token expired or is missing | @csrf in the form, or a page left open too long |
When the browser only says "500"
A 500 page hides the real error from visitors, which is correct for security. The real message is in your logs:
- Laravel:
storage/logs/laravel.log. Show the newest lines withtail -n 50 storage/logs/laravel.log. - Your browser: open developer tools, the Console tab for JavaScript errors and the Network tab for failed requests.
On your own computer, Laravel shows a detailed error page when APP_DEBUG=true in .env. On a live server, it must be false, because the detailed page can reveal secrets to anyone.
A debugging routine you can trust
- Read the whole message. Out loud if it helps.
- Find the first line in your own code in the stack trace.
- Form a guess: "I think
$totalis never set when the cart is empty." - Test the guess with one change, or by printing the value just before the line (
dd($total)in Laravel,console.log(user)in JavaScript). - Run again and read the new message. A different error is progress.
- When it works, understand why before moving on.

Change one thing at a time. If you change five things and it works, you will not know which one fixed it, and the bug will come back.
Searching an error well
Copy the message, but remove what is unique to your computer (your file paths, your variable names, IDs). Add the tool and version.
- Weak search:
error line 42 /home/amina/shop/app/OrderController.php - Strong search:
Laravel 13 "Undefined variable" in controller
Prefer answers from the official documentation and recent, highly voted forum answers. Check the date: an answer from many versions ago may no longer apply.
Ask your AI assistant
I am a beginner. Here is my full error message and the code around the line it mentions: [paste both]. Explain in simple words what the error means, which line is most likely the real cause, and one thing I can print to confirm it. Do not rewrite my whole file.
Key takeaways
- Every error tells you what, where and how you got there.
- In a stack trace, read from the top and stop at the first line in your own code.
- A 500 page hides the details; the real message is in the logs.
- Change one thing at a time, and treat a new error as progress.
- Search the message without your personal paths, plus the tool and version.
Check your understanding

Every lesson stays free. Tap the thumbs up so we know what works, or say thanks with a soda or a coffee: it pays for hosting and new lessons.
Related

How the web works
What happens between typing an address and seeing a page, explained from zero, and how to watch it in the Network tab.

How to start coding: a plan for complete beginners
Which language first, what to install, how many hours, and the order to learn things in, so you build real projects instead of watching tutorials forever.


