Skip to content

Commit

Permalink
Error handling v4
Browse files Browse the repository at this point in the history
  • Loading branch information
notnotmelon committed May 12, 2024
1 parent 5b2b48a commit fb151ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
11 changes: 10 additions & 1 deletion prototypes/functions/auto_tech.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,19 @@ function auto_tech:topo_sort_with_sp(fg, sp_graph, science_packs)
local ts = fz_topo.create(fg)
local error_found, errors = ts:run(false, self.verbose_logging)

if error_found then
log('RESTARTING WITHOUT SP LINKS')
for _, link in pairs(sp_links) do
fg:remove_link(link.from, link.to, link.from.name)
end
ts = fz_topo.create(fg)
error_found, errors = ts:run(false, self.verbose_logging)
end

local error_message
if error_found then
error_message = ""
for _, key in pairs(errors) do
for key, _ in pairs(errors) do
error_message = error_message .. key .. "\n"
end
end
Expand Down
26 changes: 1 addition & 25 deletions prototypes/functions/fz_topo_sort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,7 @@ function fz_topo:run(check_ancestry, logging)
end

local has_error = table.any(self.graph.nodes, function (n) return not n.ignore_for_dependencies and not self.sorted[n.key] end)

local errors = {}
if has_error then
for to_key, _ in pairs(recipes_with_issues) do
if to_key:find('item|') then
local node = self.graph:get_node(to_key)
local i = 0
local j = 0
local has = ''
local missing = ''
for _, e in self.graph:iter_links_to(node) do
if not self.sorted[e:from()] then
j = j + 1
missing = missing .. e:from() .. ' '
else
has = has .. e:from() .. ' '
i = i + 1
end
end
errors[#errors+1] = (to_key .. " has " .. i .. " dependencies and " .. j .. " missing dependencies. Missing: " .. missing)
end
end
end

return has_error, errors
return has_error, recipes_with_issues
end


Expand Down

0 comments on commit fb151ff

Please sign in to comment.