Module:LuaTemplateBlueprint: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
Tag: Manual revert
Line 1,036: Line 1,036:
     -- Override raw country/region with normalized names if country field exists
     -- Override raw country/region with normalized names if country field exists
     if args.country and args.country ~= '' then
     if args.country and args.country ~= '' then
        -- Debug: Check if we reach the country processing code
        if template._errorContext then
            local ErrorHandling = require('Module:ErrorHandling')
            ErrorHandling.addError(template._errorContext, "BlueprintDebug",
                string.format("About to process country='%s'", args.country),
                "", false)
        end
       
         local cr = require('Module:ConfigRepository')
         local cr = require('Module:ConfigRepository')
       
        -- Debug: Check if CountryData module loads
        if template._errorContext then
            local ErrorHandling = require('Module:ErrorHandling')
            ErrorHandling.addError(template._errorContext, "ModuleLoadDebug",
                "Attempting to load CountryData module",
                "", false)
        end
       
         local cd = require('Module:CountryData')
         local cd = require('Module:CountryData')
       
        -- Debug: Check if module loaded successfully
        if template._errorContext then
            local ErrorHandling = require('Module:ErrorHandling')
            ErrorHandling.addError(template._errorContext, "ModuleLoadedDebug",
                string.format("CountryData loaded: %s", cd and "success" or "failed"),
                "", false)
        end
       
        -- Debug: Show what we're about to call
        if template._errorContext then
            local ErrorHandling = require('Module:ErrorHandling')
            ErrorHandling.addError(template._errorContext, "BeforeCallDebug",
                string.format("About to call cd.getSemanticCountryRegionProperties('%s', errorContext)", args.country),
                "", false)
        end
       
         local norm = p.protectedExecute(
         local norm = p.protectedExecute(
             template,
             template,
             'CountryData_Override',
             'CountryData_Override',
             function()  
             function() return cd.getSemanticCountryRegionProperties(args.country) end,
                -- Debug: Inside the protected function
                if template._errorContext then
                    local ErrorHandling = require('Module:ErrorHandling')
                    ErrorHandling.addError(template._errorContext, "InsideProtectedDebug",
                        "Inside protectedExecute function, about to call CountryData",
                        "", false)
                end
               
                local result = cd.getSemanticCountryRegionProperties(args.country, template._errorContext)
               
                -- Debug: Show what CountryData returned
                if template._errorContext then
                    local ErrorHandling = require('Module:ErrorHandling')
                    local resultType = type(result)
                    local resultDesc = "nil"
                    if result then
                        if resultType == "table" then
                            local count = 0
                            for _ in pairs(result) do count = count + 1 end
                            resultDesc = string.format("table with %d keys", count)
                        else
                            resultDesc = tostring(result)
                        end
                    end
                    ErrorHandling.addError(template._errorContext, "CountryDataResultDebug",
                        string.format("CountryData returned: %s (%s)", resultDesc, resultType),
                        "", false)
                end
               
                return result
            end,
             {},
             {},
             args.country
             args.country
         )
         )
       
        -- Debug: Check what protectedExecute returned
        if template._errorContext then
            local ErrorHandling = require('Module:ErrorHandling')
            ErrorHandling.addError(template._errorContext, "ProtectedExecuteDebug",
                string.format("protectedExecute returned: %s", norm and "data" or "nil"),
                "", false)
        end
       
        -- Debug: Show what data CountryData actually returned
        if template._errorContext and norm then
            local ErrorHandling = require('Module:ErrorHandling')
            local dataDetails = {}
            for key, value in pairs(norm) do
                if type(value) == "table" then
                    table.insert(dataDetails, string.format("%s=[%s]", key, table.concat(value, ",")))
                else
                    table.insert(dataDetails, string.format("%s=%s", key, tostring(value)))
                end
            end
            ErrorHandling.addError(template._errorContext, "CountryDataReturnDebug",
                string.format("CountryData returned: %s", table.concat(dataDetails, " ")),
                "", false)
        end
       
         if norm then
         if norm then
             local countryKey = cr.semanticProperties.country
             local countryKey = cr.semanticProperties.country
             local regionKey = cr.semanticProperties.region
             local regionKey = cr.semanticProperties.region
           
            -- Debug: Show the property keys we're looking for
            if template._errorContext then
                local ErrorHandling = require('Module:ErrorHandling')
                ErrorHandling.addError(template._errorContext, "PropertyKeyDebug",
                    string.format("Looking for keys: country='%s' region='%s'", countryKey or "nil", regionKey or "nil"),
                    "", false)
            end
           
             if norm[countryKey] then
             if norm[countryKey] then
                 collector.properties[countryKey] = norm[countryKey]
                 collector.properties[countryKey] = norm[countryKey]
                -- Debug: Show successful assignment
                if template._errorContext then
                    local ErrorHandling = require('Module:ErrorHandling')
                    local valueStr = type(norm[countryKey]) == "table" and table.concat(norm[countryKey], ",") or tostring(norm[countryKey])
                    ErrorHandling.addError(template._errorContext, "CountryAssignDebug",
                        string.format("Assigned country: %s=%s", countryKey, valueStr),
                        "", false)
                end
             end
             end
             if norm[regionKey] then
             if norm[regionKey] then
                 collector.properties[regionKey] = norm[regionKey]
                 collector.properties[regionKey] = norm[regionKey]
                -- Debug: Show successful assignment
                if template._errorContext then
                    local ErrorHandling = require('Module:ErrorHandling')
                    local valueStr = type(norm[regionKey]) == "table" and table.concat(norm[regionKey], ",") or tostring(norm[regionKey])
                    ErrorHandling.addError(template._errorContext, "RegionAssignDebug",
                        string.format("Assigned region: %s=%s", regionKey, valueStr),
                        "", false)
                end
             end
             end
         end
         end