code: def _render_component_safely(
      component, render_func, return_error_component, *args, **kwargs
  ):
      rendered_obj = None
      try:
          rendered_obj = render_func(component, *args, **kwargs)
      except:
          if not return_error_component:
              return None
          error_str = traceback.format_exc()
          rendered_obj = SerializationErrorComponent(
              component.__class__.__name__, error_str
          ).render()
      else:
          if not (
              type(rendered_obj) == str or type(rendered_obj) == dict
          ):
              rendered_obj = SerializationErrorComponent(
                  component.__class__.__name__,
                  "Component render didn't return a `string` or `dict`",
              ).render()
          else:
              try:  # check if rendered object is json serializable.
                  json.dumps(rendered_obj)
              except (TypeError, OverflowError) as e:
                  rendered_obj = SerializationErrorComponent(
                      component.__class__.__name__,
                      "Rendered Component cannot be JSON serialized. \n\n %s"
                      % str(e),
                  ).render()
      return rendered_obj
  
imports: import traceback
  import json
  from .basic import SerializationErrorComponent
label_desc: Use image node_id 1 for calling a global function with example usage: _render_component_safely(component, render_func, return_error_component) and returns: rendered_obj, None