1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 */ 15 16 #pragma once 17 18 #include <cerrno> 19 #include <string> 20 21 #include "napi/uni_header.h" 22 23 namespace OHOS { 24 namespace DistributedFS { 25 constexpr int ERRNO_NOERR = 0; 26 27 enum ELegacy { 28 ELEGACY_INVAL = 202, 29 ELEGACY_IO = 300, 30 ELEGACY_NOENT = 301, 31 }; 32 33 enum ErrCodeSystem { 34 ERR_CODE_SYSTEM_LEGACY, 35 ERR_CODE_SYSTEM_POSIX, 36 }; 37 38 class UniError { 39 public: 40 UniError(); 41 explicit UniError(ELegacy eLegacy); 42 explicit UniError(int ePosix); 43 ~UniError() = default; 44 45 UniError &operator = (const UniError &) = default; 46 47 explicit operator bool() const; 48 49 void SetErrno(ELegacy eLegacy); 50 void SetErrno(int ePosix); 51 int GetErrno(ErrCodeSystem cs); 52 53 std::string GetDefaultErrstr(); 54 napi_value GetNapiErr(napi_env env); 55 napi_value GetNapiErr(napi_env env, std::string errMsg); 56 void ThrowErr(napi_env env); 57 void ThrowErr(napi_env env, std::string errMsg); 58 59 private: 60 int errno_ = ERRNO_NOERR; 61 ErrCodeSystem codingSystem_ = ERR_CODE_SYSTEM_POSIX; 62 }; 63 } // namespace DistributedFS 64 } // namespace OHOS