code: def _get_client_run_obj(obj, run_id, user_namespace):
      flow_name = obj.flow.name
  
      # handle error messaging for two cases
      # 1. our user tries to tag a new flow before it is run
      # 2. our user makes a typo in --namespace
      try:
          namespace(user_namespace)
          Flow(pathspec=flow_name)
      except MetaflowNotFound:
          raise CommandException(
              "No run found for *%s*. Please run the flow before tagging."
              % flow_name
          )
  
      except MetaflowNamespaceMismatch:
          raise CommandException(
              "No run found for *%s* in namespace *%s*. You can switch the namespace using --namespace"
              % (flow_name, user_namespace)
          )
  
      # throw an error with message to include latest run-id when run_id is None
      if run_id is None:
          latest_run_id = Flow(pathspec=flow_name).latest_run.id
          msg = (
              "Please specify a run-id using --run-id.\n"
              "*%s*'s latest run in namespace *%s* has id *%s*."
              % (flow_name, user_namespace, latest_run_id)
          )
          raise CommandException(msg)
      run_id_parts = run_id.split("/")
      if len(run_id_parts) == 1:
          path_spec = "%s/%s" % (flow_name, run_id)
      else:
          raise CommandException(
              "Run-id *%s* is not a valid run-id" % run_id
          )
  
      # handle error messaging for three cases
      # 1. our user makes a typo in --run-id
      # 2. our user's --run-id does not exist in the default/specified namespace
      try:
          namespace(user_namespace)
          run = Run(pathspec=path_spec)
      except MetaflowNotFound:
          raise CommandException(
              "No run *%s* found for flow *%s*" % (path_spec, flow_name)
          )
      except MetaflowNamespaceMismatch:
          msg = (
              "Run *%s* for flow *%s* does not belong to namespace *%s*\n"
              % (
                  path_spec,
                  flow_name,
                  user_namespace,
              )
          )
          raise CommandException(msg)
      return run
  
imports: import sys
  from itertools import chain
  from metaflow import namespace
  from metaflow.client import Flow, Run
  from metaflow.current import current
  from metaflow.util import resolve_identity
  from metaflow.exception import CommandException, MetaflowNotFound, MetaflowInternalError
  from metaflow.exception import MetaflowNamespaceMismatch
  from metaflow._vendor import click
label_desc: Use image node_id 5 for calling a global function with example usage: _get_client_run_obj(obj, run_id, user_namespace) and returns: run