TryBugHunt

Common errors, explained

What each error actually means, the root causes that produce it, and working fixes you can test directly in your browser.

Core Guide

How to Read a Python & JavaScript Stack Trace

Learn bottom-up vs top-down frame analysis and fast root-cause isolation.

Read guide →

Explore by Bug Pattern

Python Errors

43 guides

IndexError: list index out of range

You asked for an index the list does not have. Almost always a loop bound that is one too far, or an empty list you assumed had items.

Off-by-one errorsRead guide →

IndexError: string index out of range

Same cause as the list version: you asked for a character position the string does not have.

Off-by-one errorsRead guide →

AttributeError: 'NoneType' object has no attribute

Something returned None and you called a method on it. Usually a lookup that failed, or a function that forgot to return.

Null and undefined errorsRead guide →

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

You did arithmetic with a None. Something in the sum was missing and nobody checked.

Null and undefined errorsRead guide →

UnboundLocalError: cannot access local variable

You assigned to a name somewhere inside a function, which made it local for the whole function — including before the assignment runs.

Scope and closure bugsRead guide →

RecursionError: maximum recursion depth exceeded

A function kept calling itself without reaching a stopping condition.

Infinite loopsRead guide →

list.sort() returns None

sort() sorts in place and gives back None. Assigning its result throws the list away.

Mutation and copying bugsRead guide →

TypeError: '>' not supported between instances of 'str' and 'int'

You compared text with a number. The value arrived as a string and was never converted.

Type errorsRead guide →

TypeError: list indices must be integers or slices, not float

You used a float as an index. In Python 3, / always produces a float — even when the result looks whole.

Type errorsRead guide →

KeyError: 'key' in a Python dictionary

You looked up a key the dictionary does not have. The key in the message is the exact one that was missing — compare it character by character with what is really there.

Null and undefined errorsRead guide →

TypeError: 'NoneType' object is not subscriptable

You used [ ] on a value that is None. Something you expected to return a list or dict returned nothing.

Null and undefined errorsRead guide →

TypeError: 'NoneType' object is not iterable

You looped over, unpacked, or passed to list() a value that is None. The function you expected to return a collection returned nothing.

Null and undefined errorsRead guide →

TypeError: can only concatenate str (not "int") to str

You used + between a string and a number. Python will not guess whether you meant text or arithmetic.

Type errorsRead guide →

ValueError: invalid literal for int() with base 10

int() was given a string that is not a whole number. The message ends with the exact string it choked on.

Type errorsRead guide →

ZeroDivisionError: division by zero

You divided by something that was 0. Almost always a count or length that turned out to be zero for an input you did not test — usually an empty list.

Logic errorsRead guide →

NameError: name 'x' is not defined

Python reached a name it has never seen in this scope. A typo, a missing import, or a variable that only exists inside another function.

Scope and closure bugsRead guide →

TypeError: 'str' object does not support item assignment

You tried to change one character of a string in place. Python strings are immutable — you build a new string instead.

Mutation and copying bugsRead guide →

TypeError: 'list' object is not callable

You put ( ) after something that is not a function. Usually a built-in name like list or str has been overwritten by your own variable.

Scope and closure bugsRead guide →

RuntimeError: dictionary changed size during iteration

You added or removed keys from a dict while looping over it. Loop over a copy of the keys, or build a new dict.

Mutation and copying bugsRead guide →

Mutable default argument keeps old values

A function with a default list or dict remembers items between calls. The default is created once, when the function is defined — not on every call.

Mutation and copying bugsRead guide →

SyntaxError: invalid syntax

Python could not parse your code because it violates language rules: usually a missing colon, mismatched brackets, or using = instead of ==.

Logic errorsRead guide →

IndentationError: expected an indented block

Python expects an indented block of code directly following a colon (:), but found an empty body or mismatched whitespace.

Scope and closure bugsRead guide →

TypeError: 'dict' object is not callable

You tried to call a dictionary like a function with parentheses (), or a variable named dict shadowed the built-in dict type.

Type errorsRead guide →

AttributeError: 'list' object has no attribute

You called a method on a list that belongs to another type, such as .split(), .strip(), .lower() (strings) or .keys() (dictionaries).

Type errorsRead guide →

TypeError: object of type 'NoneType' has no len()

You called len() on a value that is None. Usually a function forgot to return its result, or a lookup returned None when nothing was found.

Null and undefined errorsRead guide →

TypeError: 'str' object is not callable

Something you are calling like a function is a string. Almost always a variable called str, input or format has replaced the built-in function with the same name.

Scope and closure bugsRead guide →

TypeError: unhashable type: 'list'

You used a list where Python needs a value that can never change: in a set, as a dictionary key, or in a set or dict lookup. Use a tuple instead.

Type errorsRead guide →

ValueError: too many values to unpack (expected 2)

The left side of an assignment names fewer variables than the right side produced. Usually a split() with an extra part, or a loop over a dictionary without .items().

Logic errorsRead guide →

AttributeError: 'str' object has no attribute

You called a method or read an attribute that this kind of object does not have: a list method on a string, a typo, or an attribute your own class never stored.

Type errorsRead guide →

TypeError: takes 0 positional arguments but 1 was given

Called on an object, a method always receives the object itself as its first argument. A method defined without self cannot accept it.

Scope and closure bugsRead guide →

TypeError: object of type 'int' has no len()

len() only measures things that contain items: strings, lists, dicts, sets. You gave it a number, or None.

Type errorsRead guide →

TypeError: sequence item 0: expected str instance, int found

str.join() only joins strings. One of the items, the first one here, is a number.

Type errorsRead guide →

ValueError: max() arg is an empty sequence

max() and min() have no answer for an empty list, so they raise. Give them a default, or handle the empty case first.

Null and undefined errorsRead guide →

ValueError: x is not in list

list.index() and list.remove() raise when the item is missing. Check with `in` first, or catch ValueError.

Null and undefined errorsRead guide →

TypeError: unsupported operand type(s) for +: 'int' and 'str'

You added a number and a string. Python will not guess whether you meant arithmetic or joining text, so convert one side.

Type errorsRead guide →

0.1 + 0.2 == 0.3 is False

Python floats are binary floating point, so 0.1 and 0.2 are stored as approximations and their sum is 0.30000000000000004.

Type errorsRead guide →

round(2.5) returns 2

Python's round() uses round-half-to-even: an exact .5 goes to the nearest even number, so 2.5 becomes 2 and 3.5 becomes 4.

Logic errorsRead guide →

list.append() returns None

append() changes the list in place and returns None. Assigning its result replaces your list with None.

Null and undefined errorsRead guide →

'is' returns False for equal strings

`is` checks whether two names point to the same object; `==` checks whether the values are equal. Use == for strings and numbers.

Logic errorsRead guide →

Changing one row of a 2D list changes them all

[[0] * cols] * rows repeats a reference to one inner list. Every row is the same object, so one assignment shows up everywhere.

Mutation and copying bugsRead guide →

'10' < '9' is True

Strings compare character by character, like a dictionary. "1" comes before "9", so "10" sorts before "9" whatever follows.

Type errorsRead guide →

bool('False') is True

bool() on a string only checks whether it is empty. Every non-empty string, including "False", "0" and "no", is True.

Type errorsRead guide →

str.strip() removes more than you asked

strip("https://") does not remove that word. It removes any of the characters h, t, p, s, : and / from both ends until it meets one that is not in the set.

Logic errorsRead guide →

JavaScript Errors

25 guides

TypeError: Cannot read properties of undefined

You read a property off something that does not exist. The crash is usually far from the real mistake — the value went missing earlier.

Null and undefined errorsRead guide →

ReferenceError: Cannot access before initialization

You used a let or const before its declaration line executed. This is the temporal dead zone.

Scope and closure bugsRead guide →

[object Promise] in output

A promise was used where its resolved value was expected — nearly always a missing await.

Async and race conditionsRead guide →

TypeError: Cannot read properties of undefined (reading 'map')

You called .map() on something that is undefined — almost always an array that has not loaded yet, or one that lives at a different path in the data than you think.

Null and undefined errorsRead guide →

TypeError: Cannot read properties of undefined (reading 'length')

You asked for .length of a value that is undefined (or null). An array index past the end, a missing argument, or a match() that found nothing.

Null and undefined errorsRead guide →

TypeError: data.map is not a function

The value exists, but it is not an array. Usually an object wrapping the array, a JSON string you have not parsed, or a NodeList.

Type errorsRead guide →

TypeError: x is not a function

You called something that is not a function — undefined, a string, an object. The message names exactly what you tried to call.

Type errorsRead guide →

TypeError: Assignment to constant variable.

You reassigned a name declared with const. Use let if the binding genuinely needs to change.

Scope and closure bugsRead guide →

ReferenceError: x is not defined

JavaScript could not find that name in any scope. A typo, a let/const used outside its block, or a browser-only global used on the server.

Scope and closure bugsRead guide →

RangeError: Maximum call stack size exceeded

A function called itself (directly or through others) with no way to stop. JavaScript's equivalent of infinite recursion.

Infinite loopsRead guide →

SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

You called res.json() or JSON.parse() on something that is not JSON — almost always an HTML error page from the server.

Type errorsRead guide →

forEach does not wait for async callbacks

forEach ignores the promises your async callback returns, so the code after the loop runs before any of the awaits finish.

Async and race conditionsRead guide →

Unexpected NaN in a JavaScript calculation

Arithmetic on undefined, or on a string that is not a clean number, produces NaN — and every calculation that touches NaN is NaN too.

Type errorsRead guide →

TypeError: Cannot set properties of undefined

You tried to set a property on a variable or object that is undefined or null (e.g. user.profile.name = 'Ada' when user.profile does not exist).

Null and undefined errorsRead guide →

TypeError: x is not iterable

You used a for...of loop or spread operator (...x) on something that is not an array, string, or iterable — most often a plain object, null, or undefined.

Type errorsRead guide →

TypeError: Failed to fetch

The browser's fetch() request failed before receiving an HTTP response: usually due to CORS policy blocking, an invalid URL, or network disconnection.

Async and race conditionsRead guide →

SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

You called response.json() on an API response that returned an HTML webpage (such as a 404 or 500 error page) instead of JSON data.

Logic errorsRead guide →

TypeError: Reduce of empty array with no initial value

You called arr.reduce() on an array that contains zero items, without passing a second argument as the initial accumulator value.

Null and undefined errorsRead guide →

0.1 + 0.2 is 0.30000000000000004

JavaScript numbers are binary floating point, and 0.1 cannot be stored exactly. The tiny error shows up when you add, compare or print.

Type errorsRead guide →

sort() puts 10 before 9

Array.prototype.sort() converts items to strings and sorts them alphabetically by default, so 10 comes before 9. Pass a compare function.

Logic errorsRead guide →

typeof null is "object"

typeof null returns "object" because of a bug in the first version of JavaScript that can never be fixed without breaking the web. Check for null with === null.

Null and undefined errorsRead guide →

getMonth() returns the wrong month

getMonth() returns 0 for January and 11 for December, while getDate() returns 1 to 31. Add 1 when displaying a month.

Off-by-one errorsRead guide →

Array(n).fill([]) shares one array

fill([]) evaluates [] once and puts that same array in every slot. Pushing to one pushes to all.

Mutation and copying bugsRead guide →

return on its own line returns undefined

JavaScript inserts a semicolon after a return that ends its line, so the function returns undefined and the value below is never reached.

Null and undefined errorsRead guide →

['1', '2', '3'].map(parseInt) returns [1, NaN, NaN]

map() passes each item's index as a second argument, and parseInt treats its second argument as the radix (number base).

Type errorsRead guide →

Not listed? Step through your code to see exactly where the value goes wrong, or read about the bug patterns behind them.