Module:Loop: Difference between revisions

Teeth (talk | contribs)
forgot to grab 3rd arg in repi
Teeth (talk | contribs)
add error handling
Line 16: Line 16:
local text = frame.args[3];
local text = frame.args[3];
if not index_var then
if not index_var then
return str._error( 'function repi expects a string as first parameter, received "' .. ( frame.args[1] or '' ) .. '"' )
return p._error( 'function repi expects a string as first parameter, received "' .. ( frame.args[1] or '' ) .. '"' )
end
end
if not repetitions then
if not repetitions then
return str._error( 'function repi expects a number as second parameter, received "' .. ( frame.args[2] or '' ) .. '"' )
return p._error( 'function repi expects a number as second parameter, received "' .. ( frame.args[2] or '' ) .. '"' )
end
end
if not text then
if not text then
return str._error( 'function repi expects a string to repeat as third parameter, received "' .. ( frame.args[2] or '' ) .. '"' )
return p._error( 'function repi expects a string to repeat as third parameter, received "' .. ( frame.args[2] or '' ) .. '"' )
end
end
str = ''
str = ''
Line 30: Line 30:
return str
return str
end
end
--[[
Helper function to handle error messages.
]]
function p._error( error_str )
local frame = mw.getCurrentFrame()
local error_category = frame.args.error_category or 'Errors reported by Module Loop'
local ignore_errors = frame.args.ignore_errors or false
local no_category = frame.args.no_category or false
if str._getBoolean(ignore_errors) then
return ''
end
local error_str = '<strong class="error">Loop Module Error: ' .. error_str .. '</strong>'
if error_category ~= '' and not str._getBoolean( no_category ) then
error_str = '[[Category:' .. error_category .. ']]' .. error_str
end
return error_str
end


return p
return p