Module:TemplateStarter: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 27: Line 27:
      
      
     -- Create error context for better error handling
     -- Create error context for better error handling
     local errorContext = ErrorHandling.createContext()
     local errorContext = ErrorHandling.createContext("TemplateStarter")
      
      
     -- Protected function to get configuration
     -- Protected function to get configuration
Line 34: Line 34:
          
          
         if not config then
         if not config then
             ErrorHandling.addError(errorContext, 'TemplateStarter.generateTemplate',
             return nil, string.format("Template type '%s' not found in ConfigRepository", templateType)
                string.format("Template type '%s' not found in ConfigRepository", templateType))
            return nil
         end
         end
          
          
         if not config.fields then
         if not config.fields then
             ErrorHandling.addError(errorContext, 'TemplateStarter.generateTemplate',
             return nil, string.format("Template type '%s' has no fields configuration", templateType)
                string.format("Template type '%s' has no fields configuration", templateType))
            return nil
         end
         end
          
          
Line 49: Line 45:
      
      
     -- Get configuration with error protection
     -- Get configuration with error protection
     local success, config = ErrorHandling.protect(errorContext, getTemplateConfig)
     local config = ErrorHandling.protect(errorContext, 'getTemplateConfig', getTemplateConfig, nil)
     if not success or not config then
     if not config then
         return "Error: " .. (ErrorHandling.formatOutput(errorContext) or "Failed to load template configuration")
         return "Error: Failed to load template configuration"
     end
     end
      
      
Line 73: Line 69:
             end
             end
         end
         end
        return true
     end
     end
      
      
     -- Process fields with error protection
     -- Process fields with error protection
     local fieldSuccess = ErrorHandling.protect(errorContext, processFields)
     ErrorHandling.protect(errorContext, 'processFields', processFields, false)
    if not fieldSuccess then
        ErrorHandling.addError(errorContext, 'TemplateStarter.generateTemplate',  
            "Failed to process template fields")
    end
      
      
     -- Close the template
     -- Close the template