From 272671349a9b3e70123b2a159de2789c18b9a249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 19 Mar 2025 16:49:23 +0800 Subject: [PATCH 1/2] close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp index 750ec0cb..f49ccf2f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp @@ -18,6 +18,7 @@ #include #include "close_core.h" +#include "error_handler.h" #include "filemgmt_libhilog.h" #include "type_converter.h" @@ -68,12 +69,15 @@ void CloseAni::CloseSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_obj auto [succ, fd] = ParseFd(env, obj); if (!succ) { HILOGE("Parse fd argument failed"); + ErrorHandler::Throw(env, EINVAL); return; } auto ret = CloseCore::DoClose(fd); if (!ret.IsSuccess()) { HILOGE("Close %d failed", fd); + const auto &err = ret.GetError(); + ErrorHandler::Throw(env, err); return; } } -- Gitee From dd2d513b3a495f8545a4f78f1e873d74f51bb346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 19 Mar 2025 17:53:00 +0800 Subject: [PATCH 2/2] test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) 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 8738e3c4..3b577f89 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 @@ -1431,6 +1431,154 @@ class FileIoImpl { // console.println("errorHandlerTest4 end"); // } +function readTextSyncErr1() { + console.println("readTextSyncErr1 begin"); + try { + let ret = readTextSync("/data/local/tmp/afafes.txt.txt"); + console.println(`readTextSyncErr1 read text a.txt, result = ${ret}`); + + } catch (error) { + console.error("readTextSyncErr1 Error!", error); + } + console.println("readTextSyncErr1 end"); +} +function readTextSyncErr2() { + console.println("readTextSyncErr2 begin"); + let options: ReadTextOptions = { + offset: -1, + } + try { + let ret = readTextSync("/data/local/tmp/a.txt", options); + console.println(`readTextSyncErr2 read text a.txt, result = ${ret}`); + + } catch (error) { + console.error("readTextSyncErr2 Error!", error); + } + console.println("readTextSyncErr2 end"); +} +function readTextErr1() { + console.println("readTextErr1 begin"); + let options: ReadTextOptions = { + offset: -1, + } + try { + let ret = await readText("/data/local/tmp/a.txt", options); + console.println(`readTextErr1 read text a.txt, result = ${ret}`); + } catch (error) { + console.error("readTextErr1 Error!", error); + } + console.println("readTextErr1 end"); +} +function readTextErr2() { + console.println("readTextErr2 begin"); + let options: ReadTextOptions = { + offset: -1, + } + readText("/data/local/tmp/a.txt", options, (err: BusinessError, data?: string) => { + if (err.code == 0 && data !== undefined) { + console.println(`readTextErr2 read text a.txt, result = ${data}`); + } else { + console.error("readTextErr2 Error!", err); + } + }); + console.println("readTextErr2 end"); +} + + +function listFileSyncErr1() { + console.println("listFileSyncErr1 begin"); + try { + let ret = listFileSync("/data/local/tmp/zx/"); + console.println(`listFileSyncErr1 /data/local/tmp/zx/, result = ${ret}`); + } catch (error) { + console.error("listFileSyncErr1 Error!", error); + } + console.println("listFileSyncErr1 end"); +} +function listFileSyncErr2() { + console.println("listFileSyncErr2 begin"); + let options: ListFileOptions = { + listNum: -1, + } + try { + let ret = listFileSync("/data/local/tmp", options); + console.println(`listFileSyncErr2 /data/local/tmp, result = ${ret}`); + + } catch (error) { + console.error("listFileSyncErr2 Error!", error); + } + console.println("listFileSyncErr2 end"); +} +function listFileErr1() { + console.println("listFileErr1 begin"); + let options: ListFileOptions = { + listNum: -1, + } + try { + let ret = await listFile("/data/local/tmp/", options); + console.println(`listFileErr1 /data/local/tmp, result = ${ret}`); + } catch (error) { + console.error("listFileErr1 Error!", error); + } + console.println("listFileErr1 end"); +} +function listFileErr2() { + console.println("listFileErr2 begin"); + let options: ListFileOptions = { + listNum: -1, + } + listFile("/data/local/tmp", options, (err: BusinessError, data?: string[]) => { + if (err.code == 0 && data !== undefined) { + console.println(`listFileErr2 /data/local/tmp, result = ${data}`); + } else { + console.error("listFileErr2 Error!", err); + } + }); + console.println("listFileErr2 end"); +} + +function closeSyncErr1() { + console.println("closeSyncErr1 begin"); + try { + closeSync(-176); + console.println(`closeSyncErr1 -176`); + } catch (error) { + console.error("closeSyncErr1 Error!", error); + } + console.println("closeSyncErr1 end"); +} +function closeSyncErr2() { + console.println("closeSyncErr2 begin"); + try { + closeSync(65536); + console.println(`closeSyncErr2 65536`); + } catch (error) { + console.error("closeSyncErr2 Error!", error); + } + console.println("closeSyncErr2 end"); +} +function closeErr1() { + console.println("listFileErr1 begin"); + try { + let ret = await close(-1); + console.println(`closeErr1 -1, result = ${ret}`); + } catch (error) { + console.error("closeErr1 Error!", error); + } + console.println("closeErr1 end"); +} +function closeErr2() { + console.println("closeErr2 begin"); + close(-1, (err: BusinessError, data?: undefined) => { + if (err.code == 0) { + console.println(`closeErr2 Succ`); + } else { + console.error("closeErr2 Error!", err); + } + }); + console.println("closeErr2 end"); +} + function main() { console.println("---------- hello ani --------------"); // accessSyncTest1(); @@ -1477,5 +1625,15 @@ function main() { // errorHandlerTest2(); // 参数校验失败 // errorHandlerTest3(); // 异步Promise // errorHandlerTest4(); // 异步callback + readTextErr1(); + readTextErr2(); + listFileSyncErr1() + listFileSyncErr2(); + listFileErr1(); + listFileErr1(); + closeSyncErr1(); + closeSyncErr2() + closeErr1(); + closeErr2(); console.println("---------- hello ani end ---------------"); } \ No newline at end of file -- Gitee