{"record":{"id":"262585b8476716e4","repo":"donnemartin/interactive-coding-challenges","slug":"word-cannot-be-none","errorCode":null,"errorMessage":"word cannot be None","messagePattern":"word cannot be None","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"graphs_trees/trie/trie.py","lineNumber":20,"sourceCode":"\n\nclass Node(object):\n\n    def __init__(self, key, parent=None, terminates=False):\n        self.key = key\n        self.terminates = False\n        self.parent = parent\n        self.children = {}\n\n\nclass Trie(object):\n\n    def __init__(self):\n        self.root = Node('')\n\n    def find(self, word):\n        if word is None:\n            raise TypeError('word cannot be None')\n        node = self.root\n        for char in word:\n            if char in node.children:\n                node = node.children[char]\n            else:\n                return None\n        return node if node.terminates else None\n\n    def insert(self, word):\n        if word is None:\n            raise TypeError('word cannot be None')\n        node = self.root\n        parent = None\n        for char in word:\n            if char in node.children:\n                node = node.children[char]\n            else:\n                node.children[char] = Node(char, parent=node)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/graphs_trees/trie/trie.py#L2-L38","documentation":"Raised by Trie.find when word is None. find walks characters of word against child maps, so None would fail at the for-loop; the guard rejects it explicitly. It is also called internally by remove, so a None there surfaces the same error.","triggerScenarios":"Calling trie.find(None); calling trie.remove(None) (remove delegates to find); passing an unfiltered search term.","commonSituations":"Search boxes or filters where the query can be unset; optional request parameters flowing into trie lookup without validation.","solutions":["Treat None query as no-match: check for None and return early instead of calling find","Default the query to an empty string when None (find('') returns root behavior, not an error)","Validate user input at the boundary before trie operations"],"exampleFix":"# before\nnode = trie.find(query)  # query may be None\n\n# after\nnode = trie.find(query) if query is not None else None","handlingStrategy":"validation","validationCode":"result = trie.find(word) if word is not None else None","typeGuard":"def is_searchable(word) -> bool:\n    return word is not None and isinstance(word, str)","tryCatchPattern":"try:\n    node = trie.find(word)\nexcept TypeError:\n    node = None  # treat None query as no match","preventionTips":["Normalize search input at the boundary (None -> skip lookup)","Remember remove() calls find(), so guard remove too"],"tags":["trie","search","none-check","typeerror"],"backgroundTag":"none-argument-rejected","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}