{"record":{"id":"325dee747f7772df","repo":"donnemartin/interactive-coding-challenges","slug":"file-system-cannot-be-none","errorCode":null,"errorMessage":"file_system cannot be None","messagePattern":"file_system cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/longest_abs_file_path/longest_path_solution.ipynb","lineNumber":138,"sourceCode":"  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Code\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"class Solution(object):\\n\",\n    \"\\n\",\n    \"    def length_longest_path(self, file_system):\\n\",\n    \"        if file_system is None:\\n\",\n    \"            raise TypeError('file_system cannot be None')\\n\",\n    \"        max_len = 0\\n\",\n    \"        path_len = {0: 0}\\n\",\n    \"        for line in file_system.splitlines():\\n\",\n    \"            name = line.lstrip('\\\\t')\\n\",\n    \"            depth = len(line) - len(name)\\n\",\n    \"            if '.' in name:\\n\",\n    \"                max_len = max(max_len, path_len[depth] + len(name))\\n\",\n    \"            else:\\n\",\n    \"                path_len[depth + 1] = path_len[depth] + len(name) + 1\\n\",\n    \"        return max_len\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Unit Test\"\n   ]","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/longest_abs_file_path/longest_path_solution.ipynb#L120-L156","documentation":"Raised by Solution.length_longest_path when file_system is None. The method calls file_system.splitlines() immediately, which would raise AttributeError on None; the guard requires a newline-separated path string up front.","triggerScenarios":"Calling length_longest_path(None) — e.g. the input string was never read (file missing, cell not run) or an optional parameter was forwarded as None.","commonSituations":"Reading the input from a file or stdin that may be absent; notebook workflows where an earlier cell defines file_system; tests of the guard.","solutions":["Pass the multiline path string, e.g. 'dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext'","Guard: if file_system is None: handle missing input before the call","Fix the reader to raise or default when the source is missing"],"exampleFix":"# before\nfs = read_input(path)  # None if file missing\nsolution.length_longest_path(fs)\n\n# after\nfs = read_input(path)\nif fs is None:\n    raise FileNotFoundError(path)\nsolution.length_longest_path(fs)","handlingStrategy":"validation","validationCode":"if file_system is None: raise ValueError('file_system is required')\nsolution.length_longest_path(file_system)","typeGuard":"def is_str(s): return isinstance(s, str)","tryCatchPattern":"try:\n    n = solution.length_longest_path(fs)\nexcept TypeError as e:\n    n = 0\n    logger.warning(e)","preventionTips":["Raise on missing files in readers instead of returning None","Default optional text args to ''"],"tags":["python","input-validation","none-check","strings","file-paths"],"backgroundTag":"none-argument-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}