let protect_function f x =
  try Result (f x)
  with e -> protect_warning e