We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
verifydb fails with debug in some cases
Using `./bin/instance verifydb -D` to check the `Data.fs` it fails in some cases:

```
Traceback (most recent call last):
  File "/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py", line 68, in verify_record
    class_info = unpickler.load()
  File "/Users/pbauer/.cache/buildout/eggs/ZODB-5.5.1-py3.7.egg/ZODB/_compat.py", line 62, in find_class
    return super(Unpickler, self).find_class(modulename, name)
ModuleNotFoundError: No module named 'Products.Archetypes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./bin/instance", line 262, in <module>
    + sys.argv[1:]))
  File "/Users/pbauer/.cache/buildout/eggs/plone.recipe.zope2instance-6.1.3-py3.7.egg/plone/recipe/zope2instance/ctl.py", line 937, in main
    c.onecmd(' '.join(options.args))
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 217, in onecmd
    return func(arg)
  File "/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py", line 31, in zopectl_entry
    verify_zodb(app, debug=options.debug)
  File "/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py", line 50, in verify_zodb
    success = verify_record(oid, data, debug)
  File "/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py", line 82, in verify_record
    pickletools.dis(pickle[pos:])
UnboundLocalError: local variable 'pos' referenced before assignment
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `Products/CMFPlone/_scripts/verifydb.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 from Zope2.Startup.run import make_wsgi_app
3 from ZODB.interfaces import IStorageCurrentRecordIteration
4 from ZODB.serialize import PersistentUnpickler
5 
6 import argparse
7 import io
8 import logging
9 import pdb
10 import pickletools
11 import sys
12 import traceback
13 import Zope2
14 
15 logger = logging.getLogger('zodbverify')
16 
17 
18 def zopectl_entry(self, arg):
19     parser = argparse.ArgumentParser(
20         prog=sys.argv[0] + ' verifydb',
21         description='Verifies that all records in the database can be loaded.',
22     )
23     parser.add_argument(
24         '-D', '--debug', action='store_true', dest='debug',
25         help='pause to debug broken pickles')
26     options = parser.parse_args(arg.split(' ') if arg else [])
27 
28     logging.basicConfig(level=logging.INFO)
29     make_wsgi_app({}, self.options.configfile)
30     app = Zope2.app()
31     verify_zodb(app, debug=options.debug)
32 
33 
34 def verify_zodb(obj, debug=False):
35     storage = obj._p_jar._db._storage
36     if not IStorageCurrentRecordIteration.providedBy(storage):
37         raise TypeError(
38             'ZODB storage {} does not implement record_iternext'.format(
39                 storage))
40 
41     logger.info('Scanning ZODB...')
42 
43     next_ = None
44     count = 0
45     errors = 0
46     while True:
47         count += 1
48         oid, tid, data, next_ = storage.record_iternext(next_)
49         logger.debug('Verifying {}'.format(oid))
50         success = verify_record(oid, data, debug)
51         if not success:
52             errors += 1
53         if next_ is None:
54             break
55 
56     logger.info(
57         'Done! Scanned {} records. '
58         'Found {} records that could not be loaded.'.format(
59             count, errors)
60     )
61 
62 
63 def verify_record(oid, data, debug=False):
64     input_file = io.BytesIO(data)
65     unpickler = PersistentUnpickler(None, persistent_load, input_file)
66     class_info = 'unknown'
67     try:
68         class_info = unpickler.load()
69         pos = input_file.tell()
70         unpickler.load()
71     except Exception:
72         input_file.seek(0)
73         pickle = input_file.read()
74         logger.info('\nCould not process {} record {}:'.format(
75             class_info,
76             repr(oid),
77         ))
78         logger.info(repr(pickle))
79         logger.info(traceback.format_exc())
80         if debug:
81             try:
82                 pickletools.dis(pickle[pos:])
83             finally:
84                 pdb.set_trace()
85         return False
86     return True
87 
88 
89 def persistent_load(ref):
90     pass
91
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/Products/CMFPlone/_scripts/verifydb.py b/Products/CMFPlone/_scripts/verifydb.py
--- a/Products/CMFPlone/_scripts/verifydb.py
+++ b/Products/CMFPlone/_scripts/verifydb.py
@@ -64,6 +64,7 @@
     input_file = io.BytesIO(data)
     unpickler = PersistentUnpickler(None, persistent_load, input_file)
     class_info = 'unknown'
+    pos = None
     try:
         class_info = unpickler.load()
         pos = input_file.tell()
@@ -77,11 +78,17 @@
         ))
         logger.info(repr(pickle))
         logger.info(traceback.format_exc())
-        if debug:
+        if debug and pos is not None:
             try:
                 pickletools.dis(pickle[pos:])
+            except Exception:
+                # ignore exceptions while disassembling the pickle since the
+                # real issue is that it references a unavailable module
+                pass
             finally:
                 pdb.set_trace()
+        elif debug and pos is None:
+            pdb.set_trace()
         return False
     return True

{"golden_diff": "diff --git a/Products/CMFPlone/_scripts/verifydb.py b/Products/CMFPlone/_scripts/verifydb.py\n--- a/Products/CMFPlone/_scripts/verifydb.py\n+++ b/Products/CMFPlone/_scripts/verifydb.py\n@@ -64,6 +64,7 @@\n     input_file = io.BytesIO(data)\n     unpickler = PersistentUnpickler(None, persistent_load, input_file)\n     class_info = 'unknown'\n+    pos = None\n     try:\n         class_info = unpickler.load()\n         pos = input_file.tell()\n@@ -77,11 +78,17 @@\n         ))\n         logger.info(repr(pickle))\n         logger.info(traceback.format_exc())\n-        if debug:\n+        if debug and pos is not None:\n             try:\n                 pickletools.dis(pickle[pos:])\n+            except Exception:\n+                # ignore exceptions while disassembling the pickle since the\n+                # real issue is that it references a unavailable module\n+                pass\n             finally:\n                 pdb.set_trace()\n+        elif debug and pos is None:\n+            pdb.set_trace()\n         return False\n     return True\n", "issue": "verifydb fails with debug in some cases\nUsing `./bin/instance verifydb -D` to check the `Data.fs` it fails in some cases:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py\", line 68, in verify_record\r\n    class_info = unpickler.load()\r\n  File \"/Users/pbauer/.cache/buildout/eggs/ZODB-5.5.1-py3.7.egg/ZODB/_compat.py\", line 62, in find_class\r\n    return super(Unpickler, self).find_class(modulename, name)\r\nModuleNotFoundError: No module named 'Products.Archetypes'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"./bin/instance\", line 262, in <module>\r\n    + sys.argv[1:]))\r\n  File \"/Users/pbauer/.cache/buildout/eggs/plone.recipe.zope2instance-6.1.3-py3.7.egg/plone/recipe/zope2instance/ctl.py\", line 937, in main\r\n    c.onecmd(' '.join(options.args))\r\n  File \"/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py\", line 217, in onecmd\r\n    return func(arg)\r\n  File \"/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py\", line 31, in zopectl_entry\r\n    verify_zodb(app, debug=options.debug)\r\n  File \"/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py\", line 50, in verify_zodb\r\n    success = verify_record(oid, data, debug)\r\n  File \"/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py\", line 82, in verify_record\r\n    pickletools.dis(pickle[pos:])\r\nUnboundLocalError: local variable 'pos' referenced before assignment\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom Zope2.Startup.run import make_wsgi_app\nfrom ZODB.interfaces import IStorageCurrentRecordIteration\nfrom ZODB.serialize import PersistentUnpickler\n\nimport argparse\nimport io\nimport logging\nimport pdb\nimport pickletools\nimport sys\nimport traceback\nimport Zope2\n\nlogger = logging.getLogger('zodbverify')\n\n\ndef zopectl_entry(self, arg):\n    parser = argparse.ArgumentParser(\n        prog=sys.argv[0] + ' verifydb',\n        description='Verifies that all records in the database can be loaded.',\n    )\n    parser.add_argument(\n        '-D', '--debug', action='store_true', dest='debug',\n        help='pause to debug broken pickles')\n    options = parser.parse_args(arg.split(' ') if arg else [])\n\n    logging.basicConfig(level=logging.INFO)\n    make_wsgi_app({}, self.options.configfile)\n    app = Zope2.app()\n    verify_zodb(app, debug=options.debug)\n\n\ndef verify_zodb(obj, debug=False):\n    storage = obj._p_jar._db._storage\n    if not IStorageCurrentRecordIteration.providedBy(storage):\n        raise TypeError(\n            'ZODB storage {} does not implement record_iternext'.format(\n                storage))\n\n    logger.info('Scanning ZODB...')\n\n    next_ = None\n    count = 0\n    errors = 0\n    while True:\n        count += 1\n        oid, tid, data, next_ = storage.record_iternext(next_)\n        logger.debug('Verifying {}'.format(oid))\n        success = verify_record(oid, data, debug)\n        if not success:\n            errors += 1\n        if next_ is None:\n            break\n\n    logger.info(\n        'Done! Scanned {} records. '\n        'Found {} records that could not be loaded.'.format(\n            count, errors)\n    )\n\n\ndef verify_record(oid, data, debug=False):\n    input_file = io.BytesIO(data)\n    unpickler = PersistentUnpickler(None, persistent_load, input_file)\n    class_info = 'unknown'\n    try:\n        class_info = unpickler.load()\n        pos = input_file.tell()\n        unpickler.load()\n    except Exception:\n        input_file.seek(0)\n        pickle = input_file.read()\n        logger.info('\\nCould not process {} record {}:'.format(\n            class_info,\n            repr(oid),\n        ))\n        logger.info(repr(pickle))\n        logger.info(traceback.format_exc())\n        if debug:\n            try:\n                pickletools.dis(pickle[pos:])\n            finally:\n                pdb.set_trace()\n        return False\n    return True\n\n\ndef persistent_load(ref):\n    pass\n", "path": "Products/CMFPlone/_scripts/verifydb.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom Zope2.Startup.run import make_wsgi_app\nfrom ZODB.interfaces import IStorageCurrentRecordIteration\nfrom ZODB.serialize import PersistentUnpickler\n\nimport argparse\nimport io\nimport logging\nimport pdb\nimport pickletools\nimport sys\nimport traceback\nimport Zope2\n\nlogger = logging.getLogger('zodbverify')\n\n\ndef zopectl_entry(self, arg):\n    parser = argparse.ArgumentParser(\n        prog=sys.argv[0] + ' verifydb',\n        description='Verifies that all records in the database can be loaded.',\n    )\n    parser.add_argument(\n        '-D', '--debug', action='store_true', dest='debug',\n        help='pause to debug broken pickles')\n    options = parser.parse_args(arg.split(' ') if arg else [])\n\n    logging.basicConfig(level=logging.INFO)\n    make_wsgi_app({}, self.options.configfile)\n    app = Zope2.app()\n    verify_zodb(app, debug=options.debug)\n\n\ndef verify_zodb(obj, debug=False):\n    storage = obj._p_jar._db._storage\n    if not IStorageCurrentRecordIteration.providedBy(storage):\n        raise TypeError(\n            'ZODB storage {} does not implement record_iternext'.format(\n                storage))\n\n    logger.info('Scanning ZODB...')\n\n    next_ = None\n    count = 0\n    errors = 0\n    while True:\n        count += 1\n        oid, tid, data, next_ = storage.record_iternext(next_)\n        logger.debug('Verifying {}'.format(oid))\n        success = verify_record(oid, data, debug)\n        if not success:\n            errors += 1\n        if next_ is None:\n            break\n\n    logger.info(\n        'Done! Scanned {} records. '\n        'Found {} records that could not be loaded.'.format(\n            count, errors)\n    )\n\n\ndef verify_record(oid, data, debug=False):\n    input_file = io.BytesIO(data)\n    unpickler = PersistentUnpickler(None, persistent_load, input_file)\n    class_info = 'unknown'\n    pos = None\n    try:\n        class_info = unpickler.load()\n        pos = input_file.tell()\n        unpickler.load()\n    except Exception:\n        input_file.seek(0)\n        pickle = input_file.read()\n        logger.info('\\nCould not process {} record {}:'.format(\n            class_info,\n            repr(oid),\n        ))\n        logger.info(repr(pickle))\n        logger.info(traceback.format_exc())\n        if debug and pos is not None:\n            try:\n                pickletools.dis(pickle[pos:])\n            except Exception:\n                # ignore exceptions while disassembling the pickle since the\n                # real issue is that it references a unavailable module\n                pass\n            finally:\n                pdb.set_trace()\n        elif debug and pos is None:\n            pdb.set_trace()\n        return False\n    return True\n\n\ndef persistent_load(ref):\n    pass\n", "path": "Products/CMFPlone/_scripts/verifydb.py"}]}