statusor.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "statusor.h"
  15. #include <glog/logging.h>
  16. #include "absl/status/status.h"
  17. namespace rlwe {
  18. namespace internal {
  19. static const char* kInvalidStatusCtorArgMessage =
  20. "Status::OK is not a valid constructor argument to StatusOr<T>";
  21. static const char* kNullObjectCtorArgMessage =
  22. "NULL is not a valid constructor argument to StatusOr<T*>";
  23. absl::Status StatusOrHelper::HandleInvalidStatusCtorArg() {
  24. LOG(DFATAL) << kInvalidStatusCtorArgMessage;
  25. return absl::InternalError(kInvalidStatusCtorArgMessage);
  26. }
  27. absl::Status StatusOrHelper::HandleNullObjectCtorArg() {
  28. LOG(DFATAL) << kNullObjectCtorArgMessage;
  29. return absl::InternalError(kNullObjectCtorArgMessage);
  30. }
  31. void StatusOrHelper::Crash(const absl::Status& status) {
  32. LOG(FATAL) << "Attempting to fetch value instead of handling error "
  33. << status.ToString().c_str();
  34. }
  35. } // namespace internal
  36. } // namespace rlwe