<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AProtect%2Fdoc</id>
	<title>Module:Protect/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AProtect%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Protect/doc&amp;action=history"/>
	<updated>2026-06-14T05:56:13Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:Protect/doc&amp;diff=479046&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Protect/doc&amp;diff=479046&amp;oldid=prev"/>
		<updated>2021-07-16T05:31:39Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Module rating|a}}&lt;br /&gt;
{{used in system}}&lt;br /&gt;
This [[Help:Lua metamodules|metamodule]] simplifies error handling in other modules. It transforms a function, which may throw an error, into a function, which returns a specified error message in that case.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
 local protect = require('Module:Protect')&lt;br /&gt;
 local protectedFunc = '''protect(''func'', ''errFormat'', ''options'')'''&lt;br /&gt;
&lt;br /&gt;
=== Arguments ===&lt;br /&gt;
&lt;br /&gt;
* ''{{code|func}}''&lt;br /&gt;
*: Function to be transformed.&lt;br /&gt;
* ''{{code|errFormat}}'' (default: {{code|'Error: %s'}})&lt;br /&gt;
*: Custom error message.&lt;br /&gt;
*: Use {{code|'%s'}} to include the message from a caught error.&lt;br /&gt;
* ''{{code|options}}'' – optional table with the following fields:&lt;br /&gt;
** {{code|raw}} (default: false)&lt;br /&gt;
**: If true, then ''{{code|errFormat}}'' will be used as is, otherwise it will be wrapped inside a tag &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** {{code|removeLocation}} (default: true)&lt;br /&gt;
**: If true, removes location information from caught error messages.&lt;br /&gt;
&lt;br /&gt;
=== Return value ===&lt;br /&gt;
&lt;br /&gt;
The resulting {{code|protectedFunc}} is a ''function'', which calls the original function ''{{code|func}}'', passing all arguments to it, and returns all its return values. If ''{{code|func}}'' throws an error, the specified error message is returned instead.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
 local protect = require('Module:Protect')&lt;br /&gt;
 &lt;br /&gt;
 local p = {}&lt;br /&gt;
 &lt;br /&gt;
 function p.main(frame)&lt;br /&gt;
     if not frame.args[1] then&lt;br /&gt;
         error('missing argument')&lt;br /&gt;
     end&lt;br /&gt;
     return frame.args[1]&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 p.main = '''protect'''(p.main)&lt;br /&gt;
 &lt;br /&gt;
 return p&lt;br /&gt;
&lt;br /&gt;
Invoking the main function without arguments will output: &amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;Error: missing argument&amp;lt;/strong&amp;gt;&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{#ifeq:{{SUBPAGENAME}}|sandbox | |&lt;br /&gt;
[[Category:Error-handling modules]]&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zoran</name></author>
	</entry>
</feed>