글

라벨이 debugging인 게시물 표시

TypeError: 'NoneType' object is not subscriptable - 10 Causes and Fixes

이미지
TypeError: 'NoneType' object is not subscriptable means you used [...] on a value that is None . Python raises this the moment you write x[0] , x["key"] , or x[1:3] and x happens to be None - the subscript operator simply does not exist on the NoneType type. The traceback tells you where the subscript happened, not where the None came from. That gap is the whole debugging problem: the real bug is usually several lines (or several functions) earlier, at the point something returned None and you assumed it returned a dict, a list, or a string. This page lists the concrete ways a None gets into a subscript - functions with a missing return , mutating methods like sort() and append() , regex search() misses, dict.get() on an absent key, JSON null , DB queries with no rows - each with a reproduction, the fix, and a way to verify. If your case does not match any of them, work the diagnostic checklist instead. Error TypeError: 'NoneType' object i...

TypeError: Cannot read properties of undefined (reading 'map') - 11 Causes and Fixes

이미지
TypeError: Cannot read properties of undefined (reading 'map') means you called .map() on something that does not exist. JavaScript evaluated the expression to the left of .map , got undefined , and stopped there. The distinction that matters: the array is not empty, it is absent . An empty array maps fine and renders nothing. undefined has no properties at all, so the property lookup itself throws before your callback ever runs. Older JavaScript engines print the same failure as Cannot read property 'map' of undefined . Same bug, older wording - everything on this page applies. Below: the one-line fix, then 11 distinct causes with a reproduction and a fix for each, then a checklist for when your case matches none of them. Error TypeError: Cannot read properties of undefined (reading 'map') Where it happens JavaScript - browser or Node.js, any framework. Most often React or Vue rendering a list from data that has not arrived, or a server response wh...