Skip to content

Commit

Permalink
fix: Nicer error messages.
Browse files Browse the repository at this point in the history
Addresses new issue in #4. But isn't beautiful enough just yet.
  • Loading branch information
odkr committed Jun 2, 2021
1 parent ef1777e commit 66e3a61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 12 additions & 10 deletions pandoc-zotxt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,12 @@ do
-- error message (for easy citekeys) or an empty response
-- (for Better BibTeX citation keys).
local query_url = concat{base_url, key_ts[i], '=', id}
local mt, data = url_read(query_url)
if mt and mt ~= '' then
assert(match(mt, utf8_p),
'Data retrieved from zotxt is not encoded in UTF-8.')
local ok, mt, data = pcall(url_read, query_url)
assert(ok, 'Could not get data from Zotero.')
assert(mt or match(mt, utf8_p),
'zotxt response is not encoded in UTF-8.')
if mt ~= '' then
-- luacheck: ignore ok
local ok, item = pcall(parse_f, data, mt)
if ok then
if i ~= 1 then
Expand Down Expand Up @@ -1440,9 +1442,9 @@ function biblio_read (fname)
if not decode then return nil, fname .. ': Cannot parse format.' end
local str, err, errno = file_read(fname)
if not str then return nil, err, errno end
local ok, items = pcall(decode, str)
if not ok then return nil, fname .. ': Parse error.' end
return items
local ok, ret = pcall(decode, str)
if not ok then return nil, fname .. ': ' .. tostring(ret) end
return ret
end


Expand Down Expand Up @@ -1473,9 +1475,9 @@ function biblio_write (fname, items)
local encode = codec.encode
if not encode then return nil, fname .. ': Cannot write format.' end
if not items or #items == 0 then return suffix end
local ok, str = pcall(encode, items)
if not ok then return nil, fname .. ': Serialisation error.' end
local ok, err, errno = file_write(fname, str, EOL)
local ok, ret = pcall(encode, items)
if not ok then return nil, fname .. ': ' .. tostring(ret) end
local ok, err, errno = file_write(fname, ret, EOL)
if not ok then return nil, err, errno end
return suffix
end
Expand Down
5 changes: 2 additions & 3 deletions test/scripts/debug-wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ function M.url_read (url)
local hash = pandoc.utils.sha1(url):sub(1, 8)
M.warnf('%s -> %s', url, hash)
local path = M.path_join(CAN_DIR, hash)
local data, err, errno = M.file_read(path)
if not data then return nil, err, errno end
return 'text/plain; charset=utf-8', data
local data = M.file_read(path)
return 'text/plain; charset=utf-8', data or '<not found>'
end

return M

0 comments on commit 66e3a61

Please sign in to comment.