diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index 465ad0150c467a496ff74e8055952bb84177fb11..9ed1bd8952e9897bb2ff4a3bb6484212cd76cb4b 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -529,6 +529,8 @@ function stat(file: string | number): Promise { let r = ret as Stat; resolve(r); } + }).catch((e: BusinessError): void => { + reject(e); }); }); } @@ -546,6 +548,8 @@ function stat(file: string | number, callback: AsyncCallback): void let r = ret as Stat; callback(err, r); } + }).catch((e: BusinessError): void => { + callback(e, new StatInner(0)); }); } @@ -626,7 +630,7 @@ enum LocationType { CLOUD = 2 } -interface Stat { +export interface Stat { ino: bigint; mode: number; uid: number; diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_ani.cpp b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_ani.cpp index 23ec937f35752867dbe1c23db21af6cf807755fa..ac78c5edffaa3e28921e1d4e30f0df854d2d9c11 100644 --- a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_ani.cpp @@ -18,6 +18,7 @@ #include #include +#include "error_handler.h" #include "filemgmt_libhilog.h" #include "stat_core.h" #include "type_converter.h" @@ -191,12 +192,15 @@ ani_object StatAni::StatSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani auto [succPath, fileInfo] = TypeConverter::ToFileInfo(env, file); if (!succPath) { HILOGE("The first argument requires filepath/fd"); + ErrorHandler::Throw(env, EINVAL); return {}; } auto ret = StatCore::DoStat(fileInfo); if (!ret.IsSuccess()) { HILOGE("DoStat failed!"); + const FsError &err = ret.GetError(); + ErrorHandler::Throw(env, err); return {}; } @@ -206,8 +210,10 @@ ani_object StatAni::StatSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani delete fsStat; fsStat = nullptr; HILOGE("Wrap stat object failed!"); + ErrorHandler::Throw(env, UNKNOWN_ERR); return {}; } + return statObject; } @@ -215,6 +221,7 @@ ani_boolean StatAni::IsBlockDevice(ani_env *env, [[maybe_unused]] ani_object obj { auto fsStat = Unwrap(env, object); if (fsStat == nullptr) { + ErrorHandler::Throw(env, UNKNOWN_ERR); return ANI_FALSE; } @@ -226,6 +233,7 @@ ani_boolean StatAni::IsCharacterDevice(ani_env *env, [[maybe_unused]] ani_object { auto fsStat = Unwrap(env, object); if (fsStat == nullptr) { + ErrorHandler::Throw(env, UNKNOWN_ERR); return ANI_FALSE; } @@ -237,6 +245,7 @@ ani_boolean StatAni::IsDirectory(ani_env *env, [[maybe_unused]] ani_object objec { auto fsStat = Unwrap(env, object); if (fsStat == nullptr) { + ErrorHandler::Throw(env, UNKNOWN_ERR); return ANI_FALSE; } @@ -248,6 +257,7 @@ ani_boolean StatAni::IsFIFO(ani_env *env, [[maybe_unused]] ani_object object) { auto fsStat = Unwrap(env, object); if (fsStat == nullptr) { + ErrorHandler::Throw(env, UNKNOWN_ERR); return ANI_FALSE; } @@ -259,6 +269,7 @@ ani_boolean StatAni::IsFile(ani_env *env, [[maybe_unused]] ani_object object) { auto fsStat = Unwrap(env, object); if (fsStat == nullptr) { + ErrorHandler::Throw(env, UNKNOWN_ERR); return ANI_FALSE; } @@ -270,6 +281,7 @@ ani_boolean StatAni::IsSocket(ani_env *env, [[maybe_unused]] ani_object object) { auto fsStat = Unwrap(env, object); if (fsStat == nullptr) { + ErrorHandler::Throw(env, UNKNOWN_ERR); return ANI_FALSE; } @@ -281,6 +293,7 @@ ani_boolean StatAni::IsSymbolicLink(ani_env *env, [[maybe_unused]] ani_object ob { auto fsStat = Unwrap(env, object); if (fsStat == nullptr) { + ErrorHandler::Throw(env, UNKNOWN_ERR); return ANI_FALSE; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/copy_file_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/copy_file_ani.cpp index 161378a5736390ba992e8f11a8740f7ea930ed69..51e30f4de0053763d7b6c0d812c6c4d1b1eaf554 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/copy_file_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/copy_file_ani.cpp @@ -16,6 +16,7 @@ #include "copy_file_ani.h" #include "copy_file_core.h" +#include "error_handler.h" #include "filemgmt_libhilog.h" #include "type_converter.h" @@ -33,18 +34,22 @@ void CopyFileAni::CopyFileSync( auto [succDest, destFile] = TypeConverter::ToFileInfo(env, dest); if (!succSrc || !succDest) { HILOGE("The first/second argument requires filepath/fd"); + ErrorHandler::Throw(env, EINVAL); return; } auto [succMode, optMode] = TypeConverter::ToOptionalInt32(env, mode); if (!succMode) { HILOGE("Failed to convert mode to int32"); + ErrorHandler::Throw(env, EINVAL); return; } auto ret = CopyFileCore::DoCopyFile(srcFile, destFile, optMode); if (!ret.IsSuccess()) { HILOGE("DoCopyFile failed!"); + const FsError &err = ret.GetError(); + ErrorHandler::Throw(env, err); return; } }