<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/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://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AProtect%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Protect/doc&amp;action=history"/>
	<updated>2026-05-07T08:19:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Protect/doc&amp;diff=144523&amp;oldid=prev</id>
		<title>imported&gt;Pppery: Rv; this is the English Wikipedia, not the Turkish Wikipedia</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Protect/doc&amp;diff=144523&amp;oldid=prev"/>
		<updated>2022-09-20T21:14:07Z</updated>

		<summary type="html">&lt;p&gt;Rv; this is the English Wikipedia, not the Turkish Wikipedia&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Module rating|protected}}&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;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
 local protect = require(&amp;#039;Module:Protect&amp;#039;)&lt;br /&gt;
 local protectedFunc = protect(func, errFormat, options)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Arguments ===&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;{{code|func}}&amp;#039;&amp;#039;&lt;br /&gt;
*: Function to be transformed.&lt;br /&gt;
* &amp;#039;&amp;#039;{{code|errFormat}}&amp;#039;&amp;#039; (default: {{code|&amp;#039;Error: %s&amp;#039;}})&lt;br /&gt;
*: Custom error message.&lt;br /&gt;
*: Use {{code|&amp;#039;%s&amp;#039;}} to include the message from a caught error.&lt;br /&gt;
* &amp;#039;&amp;#039;{{code|options}}&amp;#039;&amp;#039; – optional table with the following fields:&lt;br /&gt;
** {{code|raw}} (default: false)&lt;br /&gt;
**: If true, then &amp;#039;&amp;#039;{{code|errFormat}}&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;function&amp;#039;&amp;#039;, which calls the original function &amp;#039;&amp;#039;{{code|func}}&amp;#039;&amp;#039;, passing all arguments to it, and returns all its return values. If &amp;#039;&amp;#039;{{code|func}}&amp;#039;&amp;#039; throws an error, the specified error message is returned instead.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local protect = require(&amp;#039;Module:Protect&amp;#039;)&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(&amp;#039;missing argument&amp;#039;)&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;
&amp;lt;/syntaxhighlight&amp;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>imported&gt;Pppery</name></author>
	</entry>
</feed>