From cd1323f4590b51b092da2c69d44853e1185e3c40 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 6 Dec 2025 00:48:14 +0800 Subject: improve hash error --- core/src/xmake/hash/md5.c | 7 +++++++ core/src/xmake/hash/sha.c | 7 +++++++ core/src/xmake/hash/xxhash.c | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c index 56f68d99e..366d72951 100644 --- a/core/src/xmake/hash/md5.c +++ b/core/src/xmake/hash/md5.c @@ -115,6 +115,13 @@ tb_int_t xm_hash_md5(lua_State *lua) { } if (!ok) { lua_pushnil(lua); + // check if file exists to provide more specific error message + if (!tb_file_info(filename, tb_null)) { + lua_pushfstring(lua, "file not found: %s", filename); + } else { + lua_pushfstring(lua, "failed to read file: %s", filename); + } + return 2; } return 1; } diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c index 8140c796c..c06307521 100644 --- a/core/src/xmake/hash/sha.c +++ b/core/src/xmake/hash/sha.c @@ -123,6 +123,13 @@ tb_int_t xm_hash_sha(lua_State *lua) { } if (!ok) { lua_pushnil(lua); + // check if file exists to provide more specific error message + if (!tb_file_info(filename, tb_null)) { + lua_pushfstring(lua, "file not found: %s", filename); + } else { + lua_pushfstring(lua, "failed to read file: %s", filename); + } + return 2; } return 1; } diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index bd40e47c7..77bf32dfe 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -174,6 +174,13 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { } if (!ok) { lua_pushnil(lua); + // check if file exists to provide more specific error message + if (!tb_file_info(filename, tb_null)) { + lua_pushfstring(lua, "file not found: %s", filename); + } else { + lua_pushfstring(lua, "failed to read file: %s", filename); + } + return 2; } return 1; } -- cgit v1.3.1