code: def collect_exceptions(rdict_or_list, method="unspecified"):
      """check a result dict for errors, and raise CompositeError if any exist.
      Passthrough otherwise."""
      elist = []
      if isinstance(rdict_or_list, dict):
          rlist = rdict_or_list.values()
      else:
          rlist = rdict_or_list
      for r in rlist:
          if isinstance(r, RemoteError):
              en, ev, etb, ei = (
                  r.ename,
                  r.evalue,
                  r.traceback,
                  r.engine_info,
              )
              # Sometimes we could have CompositeError in our list.  Just take
              # the errors out of them and put them in our new list.  This
              # has the effect of flattening lists of CompositeErrors into one
              # CompositeError
              if en == "CompositeError":
                  for e in ev.elist:
                      elist.append(e)
              else:
                  elist.append((en, ev, etb, ei))
      if len(elist) == 0:
          return rdict_or_list
      else:
          msg = "one or more exceptions raised in: %s" % (method)
          err = CompositeError(msg, elist)
          raise err
  
imports: import builtins
  import sys
  import traceback
label_desc: Use image node_id 1 for calling a global function with example usage: collect_exceptions(rdict_or_list, method) and returns: rdict_or_list