diff --git a/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp b/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp index 9a6322550d57aafdf4c09f087597e953394f5613..28b40e35907e32ef1a9c902ce7e8be96e9224e13 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_stub_impl.cpp @@ -29,14 +29,14 @@ std::shared_ptr FileAccessExtStubImpl::GetOwner() int FileAccessExtStubImpl::OpenFile(const Uri &uri, const int flags) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "OpenFile"); - int ret = ERR_ERROR; + if (extension_ == nullptr) { HILOG_ERROR("OpenFile get extension failed."); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_EXTENSION_FAIL; } - ret = extension_->OpenFile(uri, flags); + int ret = extension_->OpenFile(uri, flags); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } @@ -44,14 +44,14 @@ int FileAccessExtStubImpl::OpenFile(const Uri &uri, const int flags) int FileAccessExtStubImpl::CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "CreateFile"); - int ret = ERR_ERROR; + if (extension_ == nullptr) { HILOG_ERROR("CreateFile get extension failed."); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_EXTENSION_FAIL; } - ret = extension_->CreateFile(parent, displayName, newFile); + int ret = extension_->CreateFile(parent, displayName, newFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } @@ -59,14 +59,14 @@ int FileAccessExtStubImpl::CreateFile(const Uri &parent, const std::string &disp int FileAccessExtStubImpl::Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Mkdir"); - int ret = ERR_ERROR; + if (extension_ == nullptr) { HILOG_ERROR("Mkdir get extension failed."); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_EXTENSION_FAIL; } - ret = extension_->Mkdir(parent, displayName, newFile); + int ret = extension_->Mkdir(parent, displayName, newFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } @@ -74,14 +74,14 @@ int FileAccessExtStubImpl::Mkdir(const Uri &parent, const std::string &displayNa int FileAccessExtStubImpl::Delete(const Uri &sourceFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Delete"); - int ret = ERR_ERROR; + if (extension_ == nullptr) { HILOG_ERROR("Delete get extension failed."); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_EXTENSION_FAIL; } - ret = extension_->Delete(sourceFile); + int ret = extension_->Delete(sourceFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } @@ -89,14 +89,14 @@ int FileAccessExtStubImpl::Delete(const Uri &sourceFile) int FileAccessExtStubImpl::Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Move"); - int ret = ERR_ERROR; + if (extension_ == nullptr) { HILOG_ERROR("Move get extension failed."); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_EXTENSION_FAIL; } - ret = extension_->Move(sourceFile, targetParent, newFile); + int ret = extension_->Move(sourceFile, targetParent, newFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } @@ -104,14 +104,14 @@ int FileAccessExtStubImpl::Move(const Uri &sourceFile, const Uri &targetParent, int FileAccessExtStubImpl::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Rename"); - int ret = ERR_ERROR; + if (extension_ == nullptr) { HILOG_ERROR("Rename get extension failed."); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_EXTENSION_FAIL; } - ret = extension_->Rename(sourceFile, displayName, newFile); + int ret = extension_->Rename(sourceFile, displayName, newFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } @@ -149,14 +149,14 @@ std::vector FileAccessExtStubImpl::GetRoots() int FileAccessExtStubImpl::IsFileExist(const Uri &uri, bool &isExist) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "IsFileExist"); - int ret = ERR_ERROR; + if (extension_ == nullptr) { HILOG_ERROR("IsFileExist get extension failed."); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_EXTENSION_FAIL; } - ret = extension_->IsFileExist(uri, isExist); + int ret = extension_->IsFileExist(uri, isExist); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 6e4eb1bdc08e06cc06ca729afadc49ce7a51bbc3..1b2408ccb1ad688a988ebac92c0673ec862637a5 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -155,14 +155,13 @@ bool FileAccessHelper::GetProxy() int FileAccessHelper::OpenFile(Uri &uri, int flags) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "OpenFile"); - int fd = ERR_ERROR; if (!GetProxy()) { HILOG_ERROR("failed with invalid fileAccessExtProxy_"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return fd; + return ERR_GET_PROXY_FAIL; } - fd = fileAccessExtProxy_->OpenFile(uri, flags); + int fd = fileAccessExtProxy_->OpenFile(uri, flags); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return fd; } @@ -170,14 +169,13 @@ int FileAccessHelper::OpenFile(Uri &uri, int flags) int FileAccessHelper::CreateFile(Uri &parent, const std::string &displayName, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "CreateFile"); - int index = ERR_ERROR; if (!GetProxy()) { HILOG_ERROR("failed with invalid fileAccessExtProxy_"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return index; + return ERR_GET_PROXY_FAIL; } - index = fileAccessExtProxy_->CreateFile(parent, displayName, newFile); + int index = fileAccessExtProxy_->CreateFile(parent, displayName, newFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return index; } @@ -185,14 +183,13 @@ int FileAccessHelper::CreateFile(Uri &parent, const std::string &displayName, Ur int FileAccessHelper::Mkdir(Uri &parent, const std::string &displayName, Uri &newDir) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Mkdir"); - int index = ERR_ERROR; - if (fileAccessExtProxy_ == nullptr) { + if (!GetProxy()) { HILOG_ERROR("failed with invalid fileAccessExtProxy_"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return index; + return ERR_GET_PROXY_FAIL; } - index = fileAccessExtProxy_->Mkdir(parent, displayName, newDir); + int index = fileAccessExtProxy_->Mkdir(parent, displayName, newDir); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return index; } @@ -200,14 +197,13 @@ int FileAccessHelper::Mkdir(Uri &parent, const std::string &displayName, Uri &ne int FileAccessHelper::Delete(Uri &selectFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Delete"); - int index = ERR_ERROR; if (!GetProxy()) { HILOG_ERROR("failed with invalid fileAccessExtProxy_"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return index; + return ERR_GET_PROXY_FAIL; } - index = fileAccessExtProxy_->Delete(selectFile); + int index = fileAccessExtProxy_->Delete(selectFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return index; } @@ -215,14 +211,13 @@ int FileAccessHelper::Delete(Uri &selectFile) int FileAccessHelper::Move(Uri &sourceFile, Uri &targetParent, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Move"); - int index = ERR_ERROR; if (!GetProxy()) { HILOG_ERROR("failed with invalid fileAccessExtProxy_"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return index; + return ERR_GET_PROXY_FAIL; } - index = fileAccessExtProxy_->Move(sourceFile, targetParent, newFile); + int index = fileAccessExtProxy_->Move(sourceFile, targetParent, newFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return index; } @@ -230,14 +225,13 @@ int FileAccessHelper::Move(Uri &sourceFile, Uri &targetParent, Uri &newFile) int FileAccessHelper::Rename(Uri &sourceFile, const std::string &displayName, Uri &newFile) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "Rename"); - int index = ERR_ERROR; if (!GetProxy()) { HILOG_ERROR("failed with invalid fileAccessExtProxy_"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return index; + return ERR_GET_PROXY_FAIL; } - index = fileAccessExtProxy_->Rename(sourceFile, displayName, newFile); + int index = fileAccessExtProxy_->Rename(sourceFile, displayName, newFile); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return index; } @@ -275,15 +269,13 @@ std::vector FileAccessHelper::GetRoots() int FileAccessHelper::IsFileExist(Uri &uri, bool &isExist) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "IsFileExist"); - int ret = ERR_ERROR; - if (!GetProxy()) { HILOG_ERROR("failed with invalid fileAccessExtProxy_"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); - return ret; + return ERR_GET_PROXY_FAIL; } - ret = fileAccessExtProxy_->IsFileExist(uri, isExist); + int ret = fileAccessExtProxy_->IsFileExist(uri, isExist); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return ret; } diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index 8a1e88068d0d25e2d9309e8f8be31f61a22c98cf..08d04a9b799c8e3a7d5d0737bcfbb81d759b0d81 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -24,6 +24,7 @@ #include "hilog_wrapper.h" #include "napi_base_context.h" #include "napi_common_fileaccess.h" +#include "napi_error.h" #include "n_val.h" #include "securec.h" #include "uri.h" @@ -46,7 +47,7 @@ static napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info i { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::TWO)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -182,14 +183,14 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) static FileAccessHelper *GetFileAccessHelper(napi_env env, napi_value thisVar) { if (thisVar == nullptr) { - NError(EINVAL).ThrowErr(env, "thisVar is nullper"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "thisVar is nullper"); return nullptr; } FileAccessHelper *fileAccessHelper = nullptr; napi_unwrap(env, thisVar, (void **)&fileAccessHelper); if (fileAccessHelper == nullptr) { - NError(EINVAL).ThrowErr(env, "fileAccessHelper is nullper"); + NapiError(ERR_GET_HELPER_FAIL).ThrowErr(env, "fileAccessHelper is nullper"); return nullptr; } return fileAccessHelper; @@ -204,13 +205,13 @@ static std::tuple, std::unique_ptr> GetRea std::unique_ptr name = nullptr; std::tie(succ, uri, std::ignore) = NVal(env, sourceFile).ToUTF8String(); if (!succ) { - NError(EINVAL).ThrowErr(env, "first parameter is Invalid"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "first parameter is Invalid"); return { false, std::move(uri), std::move(name) }; } std::tie(succ, name, std::ignore) = NVal(env, targetParent).ToUTF8String(); if (!succ) { - NError(EINVAL).ThrowErr(env, "second parameter is Invalid"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "second parameter is Invalid"); return { false, std::move(uri), std::move(name) }; } @@ -221,7 +222,7 @@ napi_value NAPI_OpenFile(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -229,14 +230,14 @@ napi_value NAPI_OpenFile(napi_env env, napi_callback_info info) std::unique_ptr uri; std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); if (!succ) { - NError(EINVAL).ThrowErr(env, "Invalid uri"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Invalid uri"); return nullptr; } int flags; std::tie(succ, flags) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); if (!succ) { - NError(EINVAL).ThrowErr(env, "Invalid flags"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Invalid flags"); return nullptr; } @@ -267,7 +268,7 @@ napi_value NAPI_OpenFile(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::THIRD]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -277,7 +278,7 @@ napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -319,7 +320,7 @@ napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::THIRD]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -329,7 +330,7 @@ napi_value NAPI_Mkdir(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -371,7 +372,7 @@ napi_value NAPI_Mkdir(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::THIRD]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -381,7 +382,7 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -389,7 +390,7 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info) std::unique_ptr uri; std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); if (!succ) { - NError(EINVAL).ThrowErr(env, "Invalid uri"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Invalid uri"); return nullptr; } @@ -420,7 +421,7 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::SECOND]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -430,7 +431,7 @@ napi_value NAPI_Move(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -473,7 +474,7 @@ napi_value NAPI_Move(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::THIRD]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -483,7 +484,7 @@ napi_value NAPI_Rename(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -525,7 +526,7 @@ napi_value NAPI_Rename(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::THIRD]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -535,7 +536,7 @@ napi_value NAPI_ListFile(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -543,7 +544,7 @@ napi_value NAPI_ListFile(napi_env env, napi_callback_info info) std::unique_ptr uri; std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); if (!succ) { - NError(EINVAL).ThrowErr(env, "Invalid uri"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Invalid uri"); return nullptr; } @@ -574,7 +575,7 @@ napi_value NAPI_ListFile(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::SECOND]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -584,7 +585,7 @@ napi_value NAPI_GetRoots(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -614,7 +615,7 @@ napi_value NAPI_GetRoots(napi_env env, napi_callback_info info) NVal cb(env, funcArg[NARG_POS::FIRST]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; @@ -624,7 +625,7 @@ napi_value NAPI_IsFileExist(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - NError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Number of arguments unmatched"); return nullptr; } @@ -632,7 +633,7 @@ napi_value NAPI_IsFileExist(napi_env env, napi_callback_info info) std::unique_ptr uri; std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); if (!succ) { - NError(EINVAL).ThrowErr(env, "Invalid uri"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "Invalid uri"); return nullptr; } @@ -664,7 +665,7 @@ napi_value NAPI_IsFileExist(napi_env env, napi_callback_info info) } NVal cb(env, funcArg[NARG_POS::SECOND]); if (!cb.TypeIs(napi_function)) { - NError(EINVAL).ThrowErr(env, "not function type"); + NapiError(ERR_INVALID_PARAM).ThrowErr(env, "not function type"); return nullptr; } return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; diff --git a/utils/file_access_framework_errno.h b/utils/file_access_framework_errno.h index 6fb3ae49bb2ef765b35245aa66aa578466e5475d..1b11213cc5b3eabaf3e1d0251105b6e6cd82c7c7 100644 --- a/utils/file_access_framework_errno.h +++ b/utils/file_access_framework_errno.h @@ -23,7 +23,7 @@ namespace FileAccessFwk { enum { MODULE_FILE_ACCESS_FRAMEWORK = 0x01 }; -constexpr ErrCode BASE_OFFSET = ErrCodeOffset(SUBSYS_FILEMANAGEMENT, MODULE_FILE_ACCESS_FRAMEWORK); +constexpr ErrCode BASE_OFFSET = -ErrCodeOffset(SUBSYS_FILEMANAGEMENT, MODULE_FILE_ACCESS_FRAMEWORK); enum { ERR_OK = 0, ERR_ERROR = -1, @@ -32,9 +32,13 @@ enum { ERR_INVALID_FD, // invalid fd ERR_INVALID_URI, // invalid uri ERR_URI_CHECK, // check uri head fail - ERR_FILEIO_FAIL, // fileio fail + ERR_SERVER_EXCEPT, // server except ERR_INVALID_PARAM, // invalid parameter - ERR_PARSER_FAIL // parser js result error + ERR_PARSER_FAIL, // parser js result error + ERR_OPERATION_NOT_PERMITTED, // Operation not permitted + ERR_GET_HELPER_FAIL, // get fileAccessHelper fail + ERR_GET_PROXY_FAIL, // get proxy fail + ERR_GET_EXTENSION_FAIL // get extension fail }; } // namespace FileAccessFwk } // namespace OHOS diff --git a/utils/napi_error.h b/utils/napi_error.h new file mode 100644 index 0000000000000000000000000000000000000000..f0e231eb5554b1659ade3f03d7bbc0390e5082f0 --- /dev/null +++ b/utils/napi_error.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NAPI_ERROR_H +#define NAPI_ERROR_H + +#include "hilog_wrapper.h" +#include "n_napi.h" +#include "n_error.h" + +namespace OHOS { +namespace FileAccessFwk { +namespace { + constexpr int ERRNO_NOERR = 0; +} +class NapiError : public OHOS::FileManagement::LibN::NError { +public: + NapiError(int ePosix) : errno_(ePosix) {} + ~NapiError() = default; + void ThrowErr(napi_env env, std::string errMsg) + { + napi_value tmp = nullptr; + napi_get_and_clear_last_exception(env, &tmp); + // Note that ace engine cannot thow errors created by napi_create_error so far + napi_status throwStatus = napi_throw_error(env, std::to_string(errno_).c_str(), errMsg.c_str()); + if (throwStatus != napi_ok) { + HILOG_WARN("Failed to throw an exception, %{public}d, code = %{public}s", throwStatus, errMsg.c_str()); + } + } +private: + int errno_ = ERRNO_NOERR; +}; +} +} +#endif \ No newline at end of file