# Buggy code
def run(self, dag):
    """Run the Unroll3qOrMore pass on `dag`.

    Args:
        dag(DAGCircuit): input dag
    Returns:
        DAGCircuit: output dag with maximum node degrees of 2
    Raises:
        QiskitError: if a 3q+ gate is not decomposable
    """
    for node in dag.multi_qubit_ops():
        # TODO: allow choosing other possible decompositions
        rule = node.op.definition
        if not rule:
            raise QiskitError(
                "Cannot unroll all 3q or more gates. "
                "No rule to expand instruction %s." % node.op.name
            )

        # hacky way to build a dag on the same register as the rule is defined
        # TODO: need anonymous rules to address wires by index
        decomposition = DAGCircuit()
        qregs = {qb.register for inst in rule for qb in inst[1]}
        cregs = {cb.register for inst in rule for cb in inst[2]}
        for qreg in qregs:
            decomposition.add_qreg(qreg)
        for creg in cregs:
            decomposition.add_creg(creg)
        for inst in rule:
            decomposition.apply_operation_back(*inst)
        decomposition = self.run(decomposition)  # recursively unroll
        dag.substitute_node_with_dag(node, decomposition)
    return dag


# Traceback (qiskit.exceptions.QiskitError)
import numpy as np
from qiskit import IBMQ, QuantumCircuit, transpile
from qiskit.extensions import UnitaryGate
provider = IBMQ.load_account()
backend = provider.get_backend('ibmq_london')  # arbitrary backend with at least 3 qubits
circuit = QuantumCircuit(3)
gate = UnitaryGate(np.eye(2 ** 3))
circuit.append(gate, range(3))
<qiskit.circuit.instructionset.InstructionSet object at 0x7ff8b93a60d0>
transpile(circuit, backend=backend)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/qiskit/compiler/transpile.py", line 210, in transpile    circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_args)))
File "/usr/local/lib/python3.8/dist-packages/qiskit/tools/parallel.py", line 105, in parallel_map
return [task(values[0], *task_args, **task_kwargs)]
File "/usr/local/lib/python3.8/dist-packages/qiskit/compiler/transpile.py", line 306, in _transpile_circuit
return pass_manager.run(circuit, callback=transpile_config['callback'],
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passmanager.py", line 214, in run
return self._run_single_circuit(circuits, output_name, callback)
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passmanager.py", line 277, in _run_single_circuit
result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/runningpassmanager.py", line 115, in run
dag = self._do_pass(pass_, dag, passset.options)
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/runningpassmanager.py", line 145, in _do_pass
dag = self._run_this_pass(pass_, dag)
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/runningpassmanager.py", line 157, in _run_this_pass
new_dag = pass_.run(dag)
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passes/basis/unroll_3q_or_more.py", line 54, in run
decomposition = self.run(decomposition)  # recursively unroll
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passes/basis/unroll_3q_or_more.py", line 54, in run
decomposition = self.run(decomposition)  # recursively unroll
File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passes/basis/unroll_3q_or_more.py", line 39, in run
raise QiskitError("Cannot unroll all 3q or more gates. "
qiskit.exceptions.QiskitError: 'Cannot unroll all 3q or more gates. No rule to expand instruction circuit9_dg.'

# Fixed code
def run(self, dag):
    """Run the Unroll3qOrMore pass on `dag`.

    Args:
        dag(DAGCircuit): input dag
    Returns:
        DAGCircuit: output dag with maximum node degrees of 2
    Raises:
        QiskitError: if a 3q+ gate is not decomposable
    """
    for node in dag.multi_qubit_ops():
        # TODO: allow choosing other possible decompositions
        rule = node.op.definition
        if not rule:
            if rule == []:  # empty node
                dag.remove_op_node(node)
                continue
            raise QiskitError(
                "Cannot unroll all 3q or more gates. "
                "No rule to expand instruction %s." % node.op.name
            )

        # hacky way to build a dag on the same register as the rule is defined
        # TODO: need anonymous rules to address wires by index
        decomposition = DAGCircuit()
        qregs = {qb.register for inst in rule for qb in inst[1]}
        cregs = {cb.register for inst in rule for cb in inst[2]}
        for qreg in qregs:
            decomposition.add_qreg(qreg)
        for creg in cregs:
            decomposition.add_creg(creg)
        for inst in rule:
            decomposition.apply_operation_back(*inst)
        decomposition = self.run(decomposition)  # recursively unroll
        dag.substitute_node_with_dag(node, decomposition)
    return dag