Skip to content

Commit

Permalink
Simplify downloader error reporting
Browse files Browse the repository at this point in the history
Instead of xpcall with debug.traceback, just use pcall for a shorter
error message.

Then, instead of catching puzzle load errors in the custom downloader
function, just try to load the puzzle, and let the download task handle
errors.
  • Loading branch information
mrichards42 committed Jun 6, 2021
1 parent cd5d08c commit 0dbcfea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
32 changes: 15 additions & 17 deletions scripts/download/default_sources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ return {
days = { true, true, true, true, true, true, true },
func = [[
assert(curl.get(puzzle.url, puzzle.filename, puzzle.curlopts))
local success, p = pcall(puz.Puzzle, puzzle.filename, import.Newsday)
if success then
p:Save(puzzle.filename) -- Save this as a puz
end
local p = puz.Puzzle(puzzle.filename, import.Newsday)
p:Save(puzzle.filename) -- Save this as a puz
]]
},

Expand Down Expand Up @@ -133,11 +131,11 @@ return {
-- Get the crossword data
local data = page2:match("rawc%s*=%s*'([^']+)'")
if data then
-- Using the data _as_ the filename is kind of a hack, but it works
local success, p = pcall(puz.Puzzle, data, import.amuselabsBase64)
if success then
p:Save(puzzle.filename) -- Save this as a jpz
end
-- Using the data _as_ the input filename is kind of a hack, but it works
local p = puz.Puzzle(data, import.amuselabsBase64)
p:Save(puzzle.filename)
else
return "Unable to find puzzle data"
end
]]
},
Expand All @@ -154,10 +152,10 @@ return {
-- Get the crossword data
local data = page:match("rawc%s*=%s*'([^']+)'")
if data then
local success, p = pcall(puz.Puzzle, data, import.amuselabsBase64)
if success then
p:Save(puzzle.filename)
end
local p = puz.Puzzle(data, import.amuselabsBase64)
p:Save(puzzle.filename)
else
return "Unable to find puzzle data"
end
]]
},
Expand Down Expand Up @@ -190,10 +188,10 @@ return {
-- Get the crossword data
local data = page2:match("rawc%s*=%s*'([^']+)'")
if data then
local success, p = pcall(puz.Puzzle, data, import.amuselabsBase64)
if success then
p:Save(puzzle.filename)
end
local p = puz.Puzzle(data, import.amuselabsBase64)
p:Save(puzzle.filename)
else
return "Unable to find puzzle data"
end
]]
},
Expand Down
4 changes: 2 additions & 2 deletions scripts/download/download_task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ local function download(puzzle)
-- which case we should differentiate between user-called asserts
-- (using myassert and ASSERT_ERROR), or an actual programming error.
ASSERT_ERROR = false
local success, result, err = xpcall(function() return func(puzzle, curl.get, myassert, mypuz) end, debug.traceback)
local success, result, err = pcall(function() return func(puzzle, curl.get, myassert, mypuz) end)
-- gc puzles
cleanup_puzzles()
-- Figure out what to return
Expand Down Expand Up @@ -352,4 +352,4 @@ return {
func,
[mgr.CLEAR]=on_clear,
[mgr.LOGIN]=on_relogin
}
}

0 comments on commit 0dbcfea

Please sign in to comment.