Module:DatasetLoader: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Module:DatasetLoader
--[[
-- Central loader for Data: JSON assets via JsonConfig or mw.loadData, cached per render
* Name: DatasetLoader
* Author: Mark W. Datysgeld
* Description: Central loader for Data: JSON assets via JsonConfig or mw.loadData, cached per render
* Notes: Tries JsonConfig extension first, then falls back to mw.loadData from Data: namespace; caches results to improve performance
]]


local DatasetLoader = {}
local DatasetLoader = {}
Line 19: Line 23:


     local data
     local data
    local loadMethod = "none"


     -- Try JsonConfig extension (mw.ext.data.get)
     -- Try JsonConfig extension (mw.ext.data.get)
Line 27: Line 30:
     if success and type(result) == 'table' then
     if success and type(result) == 'table' then
         data = result
         data = result
        loadMethod = "JsonConfig"
     else
     else
         -- Fallback to mw.loadData from Data: namespace
         -- Fallback to mw.loadData from Data: namespace
Line 35: Line 37:
         if success and type(result) == 'table' then
         if success and type(result) == 'table' then
             data = result
             data = result
            loadMethod = "mw.loadData"
         end
         end
     end
     end
Line 42: Line 43:
     if not data or type(data) ~= 'table' then
     if not data or type(data) ~= 'table' then
         data = {}
         data = {}
        loadMethod = "failed"
    end
    -- DEBUG: Log what we loaded for ASP2025
    if name == "Campaigns/ASP2025" and data.defaults then
        local ErrorHandling = require('Module:ErrorHandling')
        local context = ErrorHandling.createContext('DatasetLoader')
        ErrorHandling.addStatus(context, 'datasetLoader', 'ASP2025 loaded via ' .. loadMethod, 'Title field: "' .. tostring(data.defaults.title) .. '"')
        -- Force output the debug info immediately
        mw.log(ErrorHandling.formatCombinedOutput(context))
     end
     end