message: Do not use DCHECK in PyExceptionRegistry
diff: @@ -18,35 +18,59 @@ limitations under the License.
  #include <Python.h>
  #include "tensorflow/core/platform/logging.h"
  +#include "tensorflow/core/protobuf/error_codes.pb.h"
  namespace tensorflow {
  PyExceptionRegistry* PyExceptionRegistry::singleton_ = nullptr;
  void PyExceptionRegistry::Init(PyObject* code_to_exc_type_map) {
  - DCHECK(singleton_ == nullptr) << "PyExceptionRegistry::Init() already called";
  + CHECK(singleton_ == nullptr) << "PyExceptionRegistry::Init() already called";
  singleton_ = new PyExceptionRegistry;
  - DCHECK(PyDict_Check(code_to_exc_type_map));
  + CHECK(PyDict_Check(code_to_exc_type_map));
  PyObject* key;
  PyObject* value;
  Py_ssize_t pos = 0;
  while (PyDict_Next(code_to_exc_type_map, &pos, &key, &value)) {
  - TF_Code code = static_cast<TF_Code>(PyLong_AsLong(key));
  - singleton_->exc_types_[code] = value;
  + singleton_->exc_types_.emplace(static_cast<TF_Code>(PyLong_AsLong(key)),
  + value);
  // The exception classes should also have the lifetime of the process, but
  // incref just in case.
  Py_INCREF(value);
  }
  +
  + static const TF_Code kAllCodes[] = {TF_CANCELLED,
  + TF_UNKNOWN,
  + TF_INVALID_ARGUMENT,
  + TF_DEADLINE_EXCEEDED,
  + TF_NOT_FOUND,
  + TF_ALREADY_EXISTS,
  + TF_PERMISSION_DENIED,
  + TF_UNAUTHENTICATED,
  + TF_RESOURCE_EXHAUSTED,
  + TF_FAILED_PRECONDITION,
  + TF_ABORTED,
  + TF_OUT_OF_RANGE,
  + TF_UNIMPLEMENTED,
  + TF_INTERNAL,
  + TF_UNAVAILABLE,
  + TF_DATA_LOSS};
  + for (TF_Code code : kAllCodes) {
  + CHECK(singleton_->exc_types_.find(code) != singleton_->exc_types_.end())
  + << error::Code_Name(static_cast<error::Code>(code))
  + << " is not registered";
  + }
  }
  PyObject* PyExceptionRegistry::Lookup(TF_Code code) {
  - DCHECK(singleton_ != nullptr) << "Must call PyExceptionRegistry::Init() "
  + CHECK(singleton_ != nullptr) << "Must call PyExceptionRegistry::Init() "
  "before PyExceptionRegistry::Lookup()";
  - DCHECK_NE(code, TF_OK);
  - DCHECK(singleton_->exc_types_.find(code) != singleton_->exc_types_.end())
  + CHECK_NE(code, TF_OK);
  + auto it = singleton_->exc_types_.find(code);
  + CHECK(it != singleton_->exc_types_.end())
  << "Unknown error code passed to PyExceptionRegistry::Lookup: " << code;
  - return singleton_->exc_types_[code];
  + return it->second;
  }
  } // namespace tensorflow
  