How to tell which function is causing errors from bpy.app.handlers? Some add-ons can add their own handlers which may cause errors or even crash.

How to tell which functions are causing problems?

Asking on behalf of this report.
You can write functions which intercept the existing functions and print out information, eg:

Given the following test example:

import bpy
def test_handler_a(scene):
    print("  Some Pre Handler", scene)
bpy.app.handlers.frame_change_pre.append(test_handler_a)

def test_handler_b(scene):
    print("  Some Post Handler", scene)
bpy.app.handlers.frame_change_post.append(test_handler_b)


This script sets up intercepting functions that print out all handlers that run:

import bpy
import sys

def intercept(fn, *args):
    print("Intercepting:", fn)
    sys.stdout.flush()

    fn(*args)

    print("... done")
    sys.stdout.flush()

for attr in dir(bpy.app.handlers):
    if attr.startswith("_"):
        continue

    handler_list = getattr(bpy.app.handlers, attr)
    if not isinstance(handler_list, list):
        continue
    if not handler_list:
        continue

    print("Intercept Setup:", attr)

    handler_list[:] = [lambda *args: intercept(fn, *args) for fn in handler_list]