from typing import Any
import logging


def connected(error_value: Any) -> Any:
  """decorator for Cluster that checks connection status

  Args:
  error_value: return value on error

  Returns:
  error_value if error connecting, function return value otherwise
  """

  def check(fn):

    def wrapper(self, *args, **kwargs):
      if not self.connected:
        if not self.connect():
          logging.error('error connecting to cluster')
          return error_value
      return fn(self, *args, **kwargs)

    return wrapper

  return check