1 /** 2 * Copyright 2019 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_ERROR_H_ 18 #define MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_ERROR_H_ 19 20 #include <map> 21 #include <string> 22 #include "include/api/status.h" 23 #include "minddata/mindrecord/include/common/log_adapter.h" 24 25 namespace mindspore { 26 namespace mindrecord { 27 #define RETURN_IF_NOT_OK_MR(_s) \ 28 do { \ 29 Status __rc = (_s); \ 30 if (__rc.IsError()) { \ 31 return __rc; \ 32 } \ 33 } while (false) 34 35 #define RELEASE_AND_RETURN_IF_NOT_OK_MR(_s, _db, _in) \ 36 do { \ 37 Status __rc = (_s); \ 38 if (__rc.IsError()) { \ 39 if ((_db) != nullptr) { \ 40 sqlite3_close(_db); \ 41 } \ 42 (_in).close(); \ 43 return __rc; \ 44 } \ 45 } while (false) 46 47 #define STATUS_ERROR_MR(_error_code, _e) mindspore::Status(_error_code, __LINE__, MINDRECORD_SRC_FILE_NAME, _e) 48 49 #define RETURN_STATUS_ERROR_MR(_error_code, _e) \ 50 do { \ 51 return STATUS_ERROR_MR(_error_code, _e); \ 52 } while (false) 53 54 #define RETURN_STATUS_UNEXPECTED_MR(_e) \ 55 do { \ 56 RETURN_STATUS_ERROR_MR(StatusCode::kMDUnexpectedError, _e); \ 57 } while (false) 58 59 #define CHECK_FAIL_RETURN_UNEXPECTED_MR(_condition, _e) \ 60 do { \ 61 if (!(_condition)) { \ 62 RETURN_STATUS_UNEXPECTED_MR(_e); \ 63 } \ 64 } while (false) 65 66 #define RETURN_UNEXPECTED_IF_NULL_MR(_ptr) \ 67 do { \ 68 if ((_ptr) == nullptr) { \ 69 std::string err_msg = "The pointer[" + std::string(#_ptr) + "] is null."; \ 70 RETURN_STATUS_UNEXPECTED_MR(err_msg); \ 71 } \ 72 } while (false) 73 74 #define CHECK_FAIL_RETURN_SYNTAX_ERROR_MR(_condition, _e) \ 75 do { \ 76 if (!(_condition)) { \ 77 RETURN_STATUS_ERROR_MR(StatusCode::kMDSyntaxError, _e); \ 78 } \ 79 } while (false) 80 81 enum MSRStatus { 82 SUCCESS = 0, 83 FAILED = 1, 84 }; 85 86 } // namespace mindrecord 87 } // namespace mindspore 88 89 #endif // MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_ERROR_H_ 90