json: Improve IO-related error messages

develop
lethosor 2017-12-25 14:40:06 -05:00
parent d6a6bf008e
commit e6651171bf
1 changed files with 4 additions and 1 deletions

@ -21,6 +21,9 @@ function encode_file(data, path, ...)
end
local contents = encode(data, ...)
local f = io.open(path, 'w')
if not f then
error('Could not write to ' .. tostring(path))
end
f:write(contents)
f:close()
end
@ -32,7 +35,7 @@ end
function decode_file(path, ...)
local f = io.open(path)
if not f then
error('Could not open ' .. path)
error('Could not read from ' .. tostring(path))
end
local contents = f:read('*all')
f:close()