Module:Lorebook/Debug: Difference between revisions
Add detailed raw SMW data debugging to diagnose primary keys issue |
Escape curly braces ({/}) in debug output to prevent template invocation |
||
(5 intermediate revisions by the same user not shown) | |||
Line 84: | Line 84: | ||
local function getAllConcepts(world) | local function getAllConcepts(world) | ||
local query = | local query = { | ||
'[[Category:Concept]][[Belongs to world::' .. world .. ']]', | |||
'?Plist=plist', | |||
'?AliChat=alichat', | |||
'?Primary keys=primary', | |||
'?Secondary keys=secondary', | |||
'?Logic=logic', | |||
'?Key mode=mode', | |||
'?Parent concept=parent', | |||
'?Non-recursable=nonrec', | |||
'?Placement=placement', | |||
limit = 999 | limit = 999 | ||
}) | } | ||
local res = mw.smw.ask(query) | |||
if not res then return {} end | if not res then return {} end | ||
Line 107: | Line 109: | ||
debug_info = debug_info .. "Raw row.primary: " .. tostring(row.primary) .. " (type: " .. type(row.primary) .. ")\n" | debug_info = debug_info .. "Raw row.primary: " .. tostring(row.primary) .. " (type: " .. type(row.primary) .. ")\n" | ||
debug_info = debug_info .. "Raw row['Primary keys']: " .. tostring(row['Primary keys']) .. " (type: " .. type(row['Primary keys']) .. ")\n" | debug_info = debug_info .. "Raw row['Primary keys']: " .. tostring(row['Primary keys']) .. " (type: " .. type(row['Primary keys']) .. ")\n" | ||
-- List all keys in the row table | |||
debug_info = debug_info .. "\nAll keys in row:\n" | |||
for k, v in pairs(row) do | |||
debug_info = debug_info .. " [" .. tostring(k) .. "] = " .. tostring(v) .. " (type: " .. type(v) .. ")\n" | |||
end | |||
-- Store debug info in a global to access later | -- Store debug info in a global to access later | ||
_G._debug_row_info = debug_info | _G._debug_row_info = debug_info | ||
Line 112: | Line 121: | ||
normalized[i] = { | normalized[i] = { | ||
page = normalizeValue(row[1]), -- First element is the page title | page = normalizeValue(row[1]), -- First element is the page title | ||
plist = normalizeValue(row.plist), | plist = normalizeValue(row.plist), | ||
alichat = normalizeValue(row.alichat), | alichat = normalizeValue(row.alichat), | ||
Line 195: | Line 204: | ||
end | end | ||
if #chatChunks > 0 then | if #chatChunks > 0 then | ||
if #plistChunks > 0 then | |||
text = text .. '\n' -- Add extra newline between plist and chat sections | |||
end | |||
text = text .. table.concat(chatChunks, '\n') | text = text .. table.concat(chatChunks, '\n') | ||
end | end | ||
Line 279: | Line 291: | ||
end | end | ||
output = output .. result | -- Escape curly braces and use <pre> tag to preserve formatting | ||
if result and result ~= '' then | |||
result = result:gsub('{', '{'):gsub('}', '}') | |||
output = output .. "\n</pre>\n" | output = output .. result .. '\n</pre>\n' | ||
else | |||
output = output .. "(empty output)\n</pre>\n" | |||
end | end | ||