summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-22 00:27:58 +0800
committerruki <[email protected]>2020-02-21 20:47:51 +0800
commite1fc5066ec0b4994af3bd9f8d88c6d5fae25e3b6 (patch)
treec80207145f4326871bec915dfcd7f7d28b33cf32
parent32d7cc5b710f11905d953151e11bb498d9008fb4 (diff)
improve io.open errors
-rw-r--r--xmake/core/base/io.lua13
1 files changed, 6 insertions, 7 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index ee1553d2d..257e3ad3f 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -464,10 +464,9 @@ function io.readfile(filepath, opt)
opt = opt or {}
-- open file
- local file = io.open(filepath, "r", opt)
+ local file, errors = io.open(filepath, "r", opt)
if not file then
- -- error
- return nil, string.format("open %s failed!", filepath)
+ return nil, errors
end
-- read all
@@ -507,9 +506,9 @@ function io.writefile(filepath, data, opt)
opt = opt or {}
-- open file
- local file = io.open(filepath, "w", opt)
+ local file, errors = io.open(filepath, "w", opt)
if not file then
- return false, string.format("open %s failed!", filepath)
+ return false, errors
end
-- write all
@@ -560,7 +559,7 @@ function io.open(filepath, mode, opt)
if file then
return _file.new(filepath, file)
else
- return nil, string.format("failed to open file: %s", filepath)
+ return nil, string.format("cannot open file: %s, error: %s", filepath, os.strerror())
end
end
@@ -575,7 +574,7 @@ function io.openlock(filepath)
if lock then
return _filelock.new(filepath, lock)
else
- return nil, string.format("failed to open lock: %s", filepath)
+ return nil, string.format("cannot open lock: %s, error: %s", filepath, os.strerror())
end
end