message: Return error status rather than hard crash when control flow conditions are not met.
diff: @@ -17,10 +17,11 @@ limitations under the License.
  #include <unordered_map>
  #include <vector>
  +#include "tensorflow/core/lib/core/errors.h"
  +#include "tensorflow/core/platform/logging.h"
  #include "tensorflow/lite/toco/graph_transformations/graph_transformations.h"
  #include "tensorflow/lite/toco/model.h"
  #include "tensorflow/lite/toco/tooling_util.h"
  -#include "tensorflow/core/platform/logging.h"
  namespace toco {
  @@ -95,9 +96,17 @@ namespace toco {
  if (*input_it == switch_op->outputs[nonselected_output_index]) {
  // Let us guard our assumption that only Merge nodes consume the outputs
  // of Switch nodes:
  - CHECK(other_op->type == OperatorType::kMerge)
  - << "Found " << HelpfulOperatorTypeName(*other_op)
  - << " as non-selected output from Switch, but only Merge supported.";
  + if (other_op->type != OperatorType::kMerge) {
  + return ::tensorflow::Status(
  + ::tensorflow::error::FAILED_PRECONDITION,
  + ::absl::StrCat(
  + "Found ", HelpfulOperatorTypeName(*other_op),
  + " as non-selected output from Switch, but only "
  + "Merge supported. Control flow ops like Switch and Merge are "
  + "not generally supported. We are working on fixing this, "
  + "please see the Github issue at "
  + "https://github.com/tensorflow/tensorflow/issues/28485."));
  + }
  input_it = other_op->inputs.erase(input_it);
  } else {
  ++input_it;
  