code: def interpret_status_from_failed_execution(
      execution: metadata_store_pb2.Execution,
  ) -> status_lib.Status:
      """Interprets `Status` from given failed execution.
  
      Args:
        execution: An execution with last_known_state=FAILED.
  
      Returns:
        A `Status` object interpreted from the execution state.
  
      Raises:
        ValueError: If the given execution has `last_known_state` other than
        `FAILED`.
      """
      if not execution_lib.is_execution_failed(execution):
          raise ValueError(
              "Must be called with an execution with last_known_state = FAILED."
          )
      # If execution result is available, that will have the most proximate cause
      # for the failed execution.
      execution_result = execution_lib.get_execution_result(
          execution, ignore_parse_errors=True
      )
      if execution_result is not None:
          # We expect the error code to be non-OK but if by any chance it is OK,
          # we account it as UNKNOWN.
          error_code = execution_result.code or status_lib.Code.UNKNOWN
          error_msg = execution_result.result_message or None
      else:
          error_code_value = execution.custom_properties.get(
              constants.EXECUTION_ERROR_CODE_KEY
          )
          if error_code_value is not None:
              # If error code is set, we expect it to be non-OK. By any chance if it is
              # OK, we account it as UNKNOWN.
              error_code = (
                  data_types_utils.get_metadata_value(error_code_value)
                  or status_lib.Code.UNKNOWN
              )
          else:
              error_code = status_lib.Code.UNKNOWN
          error_msg_value = execution.custom_properties.get(
              constants.EXECUTION_ERROR_MSG_KEY
          )
          error_msg = (
              data_types_utils.get_metadata_value(error_msg_value)
              if error_msg_value is not None
              else None
          )
      error_msg = (
          textwrap.shorten(error_msg, width=512) if error_msg else None
      )
      return status_lib.Status(code=error_code, message=error_msg)
  
imports: import collections
  import itertools
  import json
  import sys
  import textwrap
  from typing import Callable, Dict, Iterable, List, MutableMapping, Optional, Sequence, Type
  import uuid
  from absl import logging
  import attr
  from tfx import types
  from tfx.dsl.compiler import constants
  from tfx.dsl.compiler import placeholder_utils
  from tfx.orchestration import data_types_utils
  from tfx.orchestration import metadata
  from tfx.orchestration import node_proto_view
  from tfx.orchestration.experimental.core import constants
  from tfx.orchestration.experimental.core import mlmd_state
  from tfx.orchestration.experimental.core import task
  from tfx.orchestration import mlmd_connection_manager
  from tfx.orchestration.portable import data_types
  from tfx.orchestration.portable import inputs_utils
  from tfx.orchestration.portable import outputs_utils
  from tfx.orchestration.portable.input_resolution import exceptions
  from tfx.orchestration.portable.mlmd import common_utils
  from tfx.orchestration.portable.mlmd import context_lib
  from tfx.orchestration.portable.mlmd import event_lib
  from tfx.orchestration.portable.mlmd import execution_lib
  from tfx.orchestration.portable.mlmd import filter_query_builder
  from tfx.proto.orchestration import pipeline_pb2
  from tfx.utils import proto_utils
  from tfx.utils import status
  from tfx.utils import typing_utils
  from tfx.orchestration.experimental.core import deployment_config_utils
  import ml_metadata
  from ml_metadata import errors
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 15 for calling a global function with example usage: interpret_status_from_failed_execution(execution) and returns: status_lib