# Buggy code
def readFile(self, fileName, root):
    """
    Read the file from the cache if possible.
    Return (s,ok,key)
    """
    trace = False and not g.unitTesting
    showHits = False
    showLines = False
    showList = False
    sfn = g.shortFileName(fileName)
    if not g.enableDB:
        if trace:
            g.trace("g.enableDB is False", fileName)
        return "", False, None
    if trace:
        g.trace("=====", root.v.gnx, "children", root.numberOfChildren(), fileName)
    s = g.readFileIntoEncodedString(fileName, silent=True)
    if s is None:
        if trace:
            g.trace("empty file contents", fileName)
        return s, False, None
    assert not g.isUnicode(s)
    if trace and showLines:
        for i, line in enumerate(g.splitLines(s)):
            print("%3d %s" % (i, repr(line)))
    # There will be a bug if s is not already an encoded string.
    key = self.fileKey(fileName, s, requireEncodedString=True)
    # Fix bug #385: use the full fileName, not root.h.
    ok = self.db and key in self.db
    if ok:
        if trace and showHits:
            g.trace("cache hit", key[-6:], sfn)
        # Delete the previous tree, regardless of the @<file> type.
        while root.hasChildren():
            root.firstChild().doDelete()
        # Recreate the file from the cache.
        aList = self.db.get(key)
        if trace and showList:
            g.printList(list(g.flatten_list(aList)))
        self.createOutlineFromCacheList(root.v, aList, fileName=fileName)
    elif trace:
        g.trace("cache miss", key[-6:], sfn)
    return s, ok, key


# Traceback (IndexError)
[a64] c:\leo.repo\leo-editor>rem leo.bat

[a64] c:\leo.repo\leo-editor>python c:\leo.repo\leo-editor\launchLeo.py --gui=qttabs --gui=qttabs leo\core\leoPy.leo leo\plugins\leoPlugins.leo c:\Users\edreamleo\ekr-projects.leo leo\doc\LeoDocs.leo

reading settings in C:/leo.repo/leo-editor/leo/config/leoSettings.leo
reading settings in C:/Users/edreamleo/.leo/myLeoSettings.leo
reading settings in c:/leo.repo/leo-editor/leo/core/leoPy.leo
reading settings in C:/leo.repo/leo-editor/leo/themes/EKRDark.leo

Leo 5.7.2 devel, build 20180423091843, Mon, Apr 23, 2018  9:18:43 AM
Git repo info: branch = devel, commit = cb0abffb9c28
Python 3.6.3, PyQt version 5.6.2
Windows 10 AMD64 (build 10.0.16299) SP0
** isPython3: True
** caching enabled

reading settings in c:/leo.repo/leo-editor/leo/core/leoPy.leo
creating recovered node: g.execGitCommand
creating recovered node: gdc.__init__ &amp; helper
creating recovered node: gdc.find_git_working_directory
Traceback (most recent call last):
File "c:\leo.repo\leo-editor\launchLeo.py", line 8, in <module>
leo.core.runLeo.run()
File "c:\leo.repo\leo-editor\leo\core\runLeo.py", line 74, in run
g.app.loadManager.load(fileName, pymacs)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2285, in load
ok = lm.doPostPluginsInit()
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2325, in doPostPluginsInit
c = lm.loadLocalFile(fn, gui=g.app.gui, old_c=None)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 3159, in loadLocalFile
c = lm.openFileByName(fn, gui, old_c, previousSettings)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 3200, in openFileByName
ok = lm.readOpenedLeoFile(c, fn, readAtFileNodesFlag, theFile)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 3375, in readOpenedLeoFile
readAtFileNodesFlag=readAtFileNodesFlag)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 884, in openLeoFile
silent=silent,
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 710, in getLeoFile
recoveryNode = fc.readExternalFiles(fileName)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 844, in readExternalFiles
c.atFileCommands.readAll(c.rootVnode(), force=False)
File "c:\leo.repo\leo-editor\leo\core\leoAtFile.py", line 758, in readAll
at.read(p, force=force)
File "c:\leo.repo\leo-editor\leo\core\leoAtFile.py", line 505, in read
s, loaded, fileKey = c.cacher.readFile(fileName, root)
File "c:\leo.repo\leo-editor\leo\core\leoCache.py", line 393, in readFile
self.createOutlineFromCacheList(root.v, aList, fileName=fileName)
File "c:\leo.repo\leo-editor\leo\core\leoCache.py", line 172, in createOutlineFromCacheList
self.checkForChangedNodes(child_tuple, fileName, parent_v)
File "c:\leo.repo\leo-editor\leo\core\leoCache.py", line 199, in checkForChangedNodes
child_v.children[i] = self.c.fileCommands.gnxDict.get(gnx)
IndexError: list assignment index out of range

# Fixed code
def readFile(self, fileName, root):
    """
    Read the file from the cache if possible.
    Return (s,ok,key)
    """
    trace = False and not g.unitTesting
    showHits = False
    showLines = False
    showList = False
    sfn = g.shortFileName(fileName)
    if not g.enableDB:
        if trace:
            g.trace("g.enableDB is False", fileName)
        return "", False, None
    if trace:
        g.trace("=====", root.v.gnx, "children", root.numberOfChildren(), fileName)
    s = g.readFileIntoEncodedString(fileName, silent=True)
    if s is None:
        if trace:
            g.trace("empty file contents", fileName)
        return s, False, None
    assert not g.isUnicode(s)
    if trace and showLines:
        for i, line in enumerate(g.splitLines(s)):
            print("%3d %s" % (i, repr(line)))
    # There will be a bug if s is not already an encoded string.
    key = self.fileKey(fileName, s, requireEncodedString=True)
    # Fix bug #385: use the full fileName, not root.h.
    ok = self.db and key in self.db
    if ok:
        if trace and showHits:
            g.trace("cache hit", key[-6:], sfn)
        # Delete the previous tree, regardless of the @<file> type.
        while root.hasChildren():
            root.firstChild().doDelete()
        # Recreate the file from the cache.
        aList = self.db.get(key)
        if trace and showList:
            g.printList(list(g.flatten_list(aList)))
        self.collectChangedNodes(root.v, aList, fileName)
        self.createOutlineFromCacheList2(root.v, aList)
        # self.createOutlineFromCacheList(root.v, aList, fileName=fileName)
    elif trace:
        g.trace("cache miss", key[-6:], sfn)
    return s, ok, key