def _decode_tensor_name(tensor_name: str, error_msg: str):
  """
  Args:
    tensor_name: TensorFlow-format name ('node name:input num', or 'node
      name' as shorthand for 'node name:0')
    error_msg: Format string for raising errors. Must be able to
      serve as an input to `str.format()` with two arguments: tensor name
      string and reason for failure.

  Returns: (node name, output index) tuple identifying the tensor

  Raises ValueError if the name is not properly formatted
  """
  if ":" in tensor_name:
    node_name, output_ix_str = tensor_name.split(":")
    if not output_ix_str.isdigit():
      raise ValueError(error_msg.format(
        tensor_name, "Invalid output index string '{}'.".format(output_ix_str)
      ))
    output_ix = int(output_ix_str)
  else:
    node_name = tensor_name
    output_ix = 0

  return node_name, output_ix