Repository: plone/Products.CMFPlone

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
```


Discussion:
Another uncaught error when trying to unpickle:

```
INFO:zodbverify:Traceback (most recent call last):
  File "/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py", line 71, in verify_record
    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 'plone.app.blob'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc1-py3.7.egg/Products/CMFPlone/_scripts/verifydb.py", line 83, in verify_record
    pickletools.dis(pickle[pos:])
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pickletools.py", line 2453, in dis
    raise ValueError(errormsg)
ValueError: memo key 0 has never been stored into
```

Resolving patch:
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 @@ def verify_record(oid, data, debug=False):
     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 @@ def verify_record(oid, data, debug=False):
         ))
         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
 


Test patch: