input: Write a function in Python that takes a list of objects and returns a list of those objects sorted by one of their attributes. If the specified attribute does not exist in any of the objects, the function should raise a ValueError.
  
  def sort_by_attr(objects, attr):
      for obj in objects:
          if attr not in obj:
              raise ValueError(f"Attribute '{attr}' not found in all objects")
      return sorted(objects, key=lambda item: item[attr])
  
  assert sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "age") == [{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  assert sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "name") == [{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  assert sort_by_attr([{"name": "David", "age": 24}, {"name": "Charlie", "age": 22}], "age") == [{"name": "Charlie", "age": 22}, {"name": "David", "age": 24}]
  assert sort_by_attr([{"name": "David", "age": 24}, {"name": "Charlie", "age": 22}], "name") == [{"name": "Charlie", "age": 22}, {"name": "David", "age": 24}]
  try:
      sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob"}], "age")
      assert False, "Expected ValueError"
  except ValueError:
      pass
output: def sort_by_attr(objects, attr):
      for obj in objects:
          if attr not in obj:
              raise ValueError(f"Attribute '{attr}' not found in all objects")
      return sorted(objects, key=lambda item: item[attr])