Skip to content

Commit cd1323f

Browse files
committed
improve hash error
1 parent 741f725 commit cd1323f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

core/src/xmake/hash/md5.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ tb_int_t xm_hash_md5(lua_State *lua) {
115115
}
116116
if (!ok) {
117117
lua_pushnil(lua);
118+
// check if file exists to provide more specific error message
119+
if (!tb_file_info(filename, tb_null)) {
120+
lua_pushfstring(lua, "file not found: %s", filename);
121+
} else {
122+
lua_pushfstring(lua, "failed to read file: %s", filename);
123+
}
124+
return 2;
118125
}
119126
return 1;
120127
}

core/src/xmake/hash/sha.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ tb_int_t xm_hash_sha(lua_State *lua) {
123123
}
124124
if (!ok) {
125125
lua_pushnil(lua);
126+
// check if file exists to provide more specific error message
127+
if (!tb_file_info(filename, tb_null)) {
128+
lua_pushfstring(lua, "file not found: %s", filename);
129+
} else {
130+
lua_pushfstring(lua, "failed to read file: %s", filename);
131+
}
132+
return 2;
126133
}
127134
return 1;
128135
}

core/src/xmake/hash/xxhash.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ tb_int_t xm_hash_xxhash(lua_State *lua) {
174174
}
175175
if (!ok) {
176176
lua_pushnil(lua);
177+
// check if file exists to provide more specific error message
178+
if (!tb_file_info(filename, tb_null)) {
179+
lua_pushfstring(lua, "file not found: %s", filename);
180+
} else {
181+
lua_pushfstring(lua, "failed to read file: %s", filename);
182+
}
183+
return 2;
177184
}
178185
return 1;
179186
}

0 commit comments

Comments
 (0)