Ticket #1374: errorReport.patch

File errorReport.patch, 2.3 KB (added by s0600204, 10 years ago)

Slightly cleaner error handling for failed JSON parsing

  • gui/common/functions_civinfo.js

     
    1414    for each (var filename in civFiles)
    1515    {   // Parse data if valid file
    1616        var data = parseJSONData(filename);
     17        if (Object.keys(data).length == 0)
     18            continue;
    1719        translateObjectKeys(data, ["Name", "Description", "History", "Special"]);
    1820        civData[data.Code] = data;
    1921    }
  • simulation/components/TechnologyTemplateManager.js

     
    1919{
    2020    if (!this.allTechs[template])
    2121    {
    22         this.allTechs[template] = Engine.ReadJSONFile("technologies/" + template + ".json");
    23         if (!this.allTechs[template])
    24             error("Failed to load technology \"" + template + "\"");
     22        try
     23        {
     24            this.allTechs[template] = Engine.ReadJSONFile("technologies/" + template + ".json");
     25        }
     26        catch (err)
     27        {
     28            error(sprintf("%(error)s: parsing JSON data in %(path)s", { error: err.toString(), path: pathname }));
     29            this.allTechs[template] = false;
     30        }
    2531    }
    2632
    2733    return this.allTechs[template];
  • simulation/components/TechnologyManager.js

     
    283283
    284284    if (!template)
    285285    {
    286         error("Tried to research invalid techonology: " + uneval(tech));
     286        error("Tried to research invalid technology: " + uneval(tech));
    287287        return;
    288288    }
    289289
  • simulation/components/ProductionQueue.js

     
    241241            // Find the template data so we can determine the build costs
    242242            var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    243243            var template = cmpTempMan.GetTemplate(templateName);
    244             if (!template)
     244            if (!template || Object.keys(template) == 0)
    245245                return;
    246246            if (template.Promotion)
    247247            {