Fixes: #5376, errbacks called before accessing nonexistent objects

This is just a simple patch to prevent the crash and make the actual error more visible.