code: def _diff(
      result: Dict[str, "Result"],
      old_rev: str,
      new_rev: str,
      **kwargs,
  ) -> DiffResult:
      old = result.get(old_rev, {})
      new = result.get(new_rev, {})
  
      old_data = old.get("data", {})
      new_data = new.get("data", {})
  
      res = DiffResult()
      errors = res.setdefault("errors", {})
  
      if old_error := old.get("error"):
          errors[old_rev] = old_error
      else:
          errors[old_rev] = {
              f: d["error"] for f, d in old_data.items() if "error" in d
          }
  
      if new_error := new.get("error"):
          errors[new_rev] = new_error
      else:
          errors[new_rev] = {
              f: d["error"] for f, d in new_data.items() if "error" in d
          }
  
      diff_data = _diff_dict(
          format_dict(old_data), format_dict(new_data), **kwargs
      )
      res = DiffResult(errors=errors, diff=diff_data)
      res["errors"] = compact(res.get("errors", {}))  # type: ignore[assignment]
      return compact(res)
  
file_path: dvc/dvc/repo/metrics/diff.py
imports: from typing import TYPE_CHECKING, Dict, TypedDict, Union
  from funcy import compact
  from dvc.utils.diff import diff
  from dvc.utils.diff import format_dict
label_desc: Use image node_id 1 for calling a global function with example usage: _diff(result, old_rev, new_rev) and returns: compact