Module:DatasetLoader: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
Tag: Manual revert
Line 19: Line 19:


     local data
     local data
    local loadMethod = "none"


     -- Try JsonConfig extension (mw.ext.data.get)
     -- Try JsonConfig extension (mw.ext.data.get)
Line 27: Line 26:
     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 33:
         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 39:
     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 any Campaign request
    if name:match("Campaigns/") then
        local ErrorHandling = require('Module:ErrorHandling')
        local context = ErrorHandling.createContext('DatasetLoader')
        ErrorHandling.addStatus(context, 'datasetLoader', 'Campaign request: "' .. name .. '" via ' .. loadMethod, 'FullName: "' .. fullName .. '"')
       
        if data and type(data) == "table" then
            if data.defaults then
                local titleValue = data.defaults.title or "MISSING"
                ErrorHandling.addStatus(context, 'datasetLoader', 'Campaign data structure found', 'Title field: "' .. tostring(titleValue) .. '"')
            else
                local keys = {}
                for k, v in pairs(data or {}) do
                    table.insert(keys, tostring(k))
                end
                ErrorHandling.addStatus(context, 'datasetLoader', 'Campaign data loaded but no defaults', 'Keys: ' .. table.concat(keys, ", "))
            end
        else
            ErrorHandling.addStatus(context, 'datasetLoader', 'Campaign data load failed', 'Data type: ' .. type(data))
        end
       
        -- Force output the debug info immediately
        mw.log(ErrorHandling.formatCombinedOutput(context))
     end
     end