Skip to content

Commit e2b47ec

Browse files
authored
Add better messaging around cloud files being unavailable (#1534)
1 parent ff316b7 commit e2b47ec

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed

runtime/lua/xml.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function xml.LoadXMLFile(fileName)
102102
local fileText = fileHnd:read("*a")
103103
fileHnd:close()
104104
if not fileText then
105-
return nil, fileName.." file returns nil. OneDrive?"
105+
return nil, fileName.." file returns nil"
106106
elseif fileText == "" then
107107
return nil, fileName.." file is empty"
108108
end

src/HeadlessWrapper.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function PCall(func, ...)
142142
return nil, unpack(ret)
143143
else
144144
return ret[2]
145-
end
145+
end
146146
end
147147
function ConPrintf(fmt, ...)
148148
-- Optional
@@ -157,6 +157,13 @@ function SetProfiling(isEnabled) end
157157
function Restart() end
158158
function Exit() end
159159

160+
---@return string? provider
161+
---@return string? version
162+
---@return number? status
163+
function GetCloudProvider(fullPath)
164+
return nil, nil, nil
165+
end
166+
160167
local l_require = require
161168
function require(name)
162169
-- Hack to stop it looking for lcurl, which we don't really need

src/Modules/Build.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,11 +2157,11 @@ end
21572157
function buildMode:LoadDB(xmlText, fileName)
21582158
-- Parse the XML
21592159
local dbXML, errMsg = common.xml.ParseXML(xmlText)
2160-
if not dbXML then
2161-
launch:ShowErrMsg("^1Error loading '%s': %s", fileName, errMsg)
2160+
if errMsg and errMsg:match(".*file returns nil") then
2161+
main:OpenCloudErrorPopup(fileName)
21622162
return true
2163-
elseif #dbXML == 0 then
2164-
main:OpenMessagePopup("Error", "Build file is empty, or error parsing xml.\n\n"..fileName)
2163+
elseif errMsg then
2164+
launch:ShowErrMsg("^1"..errMsg)
21652165
return true
21662166
elseif dbXML[1].elem ~= "PathOfBuilding2" then
21672167
launch:ShowErrMsg("^1Error parsing '%s': 'PathOfBuilding2' root element missing", fileName)

src/Modules/BuildList.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ function listMode:BuildList()
216216
if fileHnd then
217217
local fileText = fileHnd:read("*a")
218218
fileHnd:close()
219+
if not fileText then
220+
main:OpenCloudErrorPopup(build.fullFileName)
221+
return
222+
end
219223
fileText = fileText:match("(<Build.->)")
220224
if fileText then
221225
local xml = common.xml.ParseXML(fileText.."</Build>")

src/Modules/Main.lua

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function main:Init()
106106
self.POESESSID = ""
107107
--self.showPublicBuilds = true
108108
self.showFlavourText = true
109+
self.errorReadingSettings = false
109110

110111
if self.userPath then
111112
self:ChangeUserPath(self.userPath, ignoreBuild)
@@ -506,9 +507,16 @@ function main:CallMode(func, ...)
506507
end
507508

508509
function main:LoadSettings(ignoreBuild)
510+
if self.errorReadingSettings then
511+
return true
512+
end
509513
local setXML, errMsg = common.xml.LoadXMLFile(self.userPath.."Settings.xml")
510-
if errMsg and not errMsg:match(".*No such file or directory") then
511-
ConPrintf("Error: '%s'", errMsg)
514+
if errMsg and errMsg:match(".*file returns nil") then
515+
self.errorReadingSettings = true
516+
self:OpenCloudErrorPopup(self.userPath.."Settings.xml")
517+
return true
518+
elseif errMsg and not errMsg:match(".*No such file or directory") then
519+
self.errorReadingSettings = true
512520
launch:ShowErrMsg("^1"..errMsg)
513521
return true
514522
end
@@ -649,9 +657,16 @@ function main:LoadSettings(ignoreBuild)
649657
end
650658

651659
function main:LoadSharedItems()
660+
if self.errorReadingSettings then
661+
return true
662+
end
652663
local setXML, errMsg = common.xml.LoadXMLFile(self.userPath.."Settings.xml")
653-
if errMsg and not errMsg:match(".*No such file or directory") then
654-
ConPrintf("Error: '%s'", errMsg)
664+
if errMsg and errMsg:match(".*file returns nil") then
665+
self.errorReadingSettings = true
666+
self:OpenCloudErrorPopup(self.userPath.."Settings.xml")
667+
return true
668+
elseif errMsg and not errMsg:match(".*No such file or directory") then
669+
self.errorReadingSettings = true
655670
launch:ShowErrMsg("^1"..errMsg)
656671
return true
657672
end
@@ -697,6 +712,9 @@ function main:LoadSharedItems()
697712
end
698713

699714
function main:SaveSettings()
715+
if self.errorReadingSettings then
716+
return
717+
end
700718
local setXML = { elem = "PathOfBuilding2" }
701719
local mode = { elem = "Mode", attrib = { mode = self.mode } }
702720
for _, val in ipairs({ self:CallMode("GetArgs") }) do
@@ -1546,6 +1564,35 @@ function main:OpenNewFolderPopup(path, onClose)
15461564
main:OpenPopup(370, 100, "New Folder", controls, "create", "edit", "cancel")
15471565
end
15481566

1567+
-- Show an error popup if a file cannot be read due to cloud provider unavailability.
1568+
-- Help button opens a URL to PoB's GitHub wiki.
1569+
function main:OpenCloudErrorPopup(fileName)
1570+
local provider, _, status = GetCloudProvider(fileName)
1571+
ConPrintf('^1Error: file offline "%s" provider: "%s" status: "%s"', fileName or "?", provider, status)
1572+
fileName = fileName and "\n\n^8'"..fileName.."'" or ""
1573+
local version = "^8v"..launch.versionNumber..(launch.versionBranch and " "..launch.versionBranch or "")..(launch.devMode and " (dev)" or "")
1574+
local title = " ^1Error "
1575+
provider = provider or "your cloud provider"
1576+
local statusText = tostring(status) or "nil"
1577+
local msg = "\n^7Cannot read file.\n\nMake sure "..provider.." is running then restart "..APP_NAME.." and try again."..
1578+
fileName.."\nstatus: "..statusText.."\n\n"..version
1579+
local url = "https://github.com/PathOfBuildingCommunity/PathOfBuilding/wiki/CloudError"
1580+
local controls = { }
1581+
local numMsgLines = 0
1582+
for line in string.gmatch(msg .. "\n", "([^\n]*)\n") do
1583+
t_insert(controls, new("LabelControl", nil, {0, 20 + numMsgLines * 16, 0, 16}, line))
1584+
numMsgLines = numMsgLines + 1
1585+
end
1586+
controls.help = new("ButtonControl", nil, {-55, 40 + numMsgLines * 16, 80, 20}, "Help (web)", function()
1587+
OpenURL(url)
1588+
end)
1589+
controls.help.tooltipText = url
1590+
controls.close = new("ButtonControl", nil, {55, 40 + numMsgLines * 16, 80, 20}, "Ok", function()
1591+
main:ClosePopup()
1592+
end)
1593+
return self:OpenPopup(m_max(DrawStringWidth(16, "VAR", msg) + 30, 190), 70 + numMsgLines * 16, title, controls, "close")
1594+
end
1595+
15491596
function main:SetWindowTitleSubtext(subtext)
15501597
if not subtext or not self.showTitlebarName then
15511598
SetWindowTitle(APP_NAME)

0 commit comments

Comments
 (0)