code: def test_view_onerror(tmp_dir, scm, dvc):
      from dvc.exceptions import NoOutputOrStageError
  
      tmp_dir.dvc_gen({"foo": "foo"}, commit="init")
      index = Index.from_repo(dvc)
  
      with pytest.raises(NoOutputOrStageError):
          index.targets_view(["foo", "missing"])
  
      failed = []
  
      def onerror(target, exc):
          failed.append((target, exc))
  
      view = index.targets_view(["foo", "missing"], onerror=onerror)
      data = view.data["repo"]
  
      assert len(failed) == 1
      target, exc = failed[0]
      assert target == "missing"
      assert isinstance(exc, NoOutputOrStageError)
      assert len(data) == 1
      assert data[("foo",)]
  
imports: import os
  from itertools import chain
  import pytest
  from pygtrie import Trie
  from dvc.repo.index import Index
  from dvc.stage import Stage
label_desc: Use image node_id 10 for calling a global function with example usage: test_view_onerror(tmp_dir, scm, dvc) without return types