mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-21 13:09:54 +02:00
Handle non-JSON update responses
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -52,8 +52,13 @@ end
|
|||||||
-- falls back to require.
|
-- falls back to require.
|
||||||
function Check.parseRelease(jsonText, Json)
|
function Check.parseRelease(jsonText, Json)
|
||||||
Json = Json or require("src.link.Json")
|
Json = Json or require("src.link.Json")
|
||||||
local doc = Json.decode(jsonText)
|
local notJson = Json.describeUnexpected(jsonText)
|
||||||
if type(doc) ~= "table" or not doc.tag_name then
|
if notJson then return nil, notJson end
|
||||||
|
local doc, decodeErr = Json.decode(jsonText)
|
||||||
|
if type(doc) ~= "table" then
|
||||||
|
return nil, decodeErr or "no tag_name in release json"
|
||||||
|
end
|
||||||
|
if not doc.tag_name then
|
||||||
return nil, "no tag_name in release json"
|
return nil, "no tag_name in release json"
|
||||||
end
|
end
|
||||||
local version = stripV(doc.tag_name)
|
local version = stripV(doc.tag_name)
|
||||||
|
|||||||
@@ -47,6 +47,20 @@ eq(bad, nil, "non-X.Y.Z tag rejected")
|
|||||||
check(badErr ~= nil, "rejection carries an error string")
|
check(badErr ~= nil, "rejection carries an error string")
|
||||||
eq(Check.parseRelease(Json.encode({ foo = 1 })), nil, "missing tag_name rejected")
|
eq(Check.parseRelease(Json.encode({ foo = 1 })), nil, "missing tag_name rejected")
|
||||||
|
|
||||||
|
-- Network failures can return a plain-text or HTML body instead of JSON. The
|
||||||
|
-- launcher must describe that response rather than leaking the decoder's
|
||||||
|
-- low-level "unexpected character 'E'" assertion.
|
||||||
|
do
|
||||||
|
local release, err = Check.parseRelease("Error: API rate limit exceeded")
|
||||||
|
check(release == nil and tostring(err):find("not JSON", 1, true) ~= nil,
|
||||||
|
"plain-text update failure is reported as non-JSON")
|
||||||
|
release, err = Check.parseRelease("<!DOCTYPE html><html>502 Bad Gateway</html>")
|
||||||
|
check(release == nil and tostring(err):find("HTML", 1, true) ~= nil,
|
||||||
|
"HTML update failure is identified")
|
||||||
|
check(tostring(err):find("unexpected character", 1, true) == nil,
|
||||||
|
"decoder assertion is not exposed")
|
||||||
|
end
|
||||||
|
|
||||||
-- parseSums: shasum -a 256 format, tolerating the '*' binary marker, a './'
|
-- parseSums: shasum -a 256 format, tolerating the '*' binary marker, a './'
|
||||||
-- prefix and CRLF line endings; unrelated lines are skipped
|
-- prefix and CRLF line endings; unrelated lines are skipped
|
||||||
local sums =
|
local sums =
|
||||||
|
|||||||
Reference in New Issue
Block a user