Module:SafeResponse/doc

This module produces safe responses for program errors. This module can be used within Lua modules.

Description
The idea of a safe response is that all errors from inner modules can be caught at the top-level (Frame object receiving) function invoked from wikitext.

A safe response is a curated description about the problem when it happens.

Error Signatures are defined in Module:SafeResponse/Data. Error signatures should be formatted with keys 'Module/Signature'. Syntax:
 * Error Signatures Definition

The message can contain replacement slots { } where key is according to key-value pairs of the "format" field of the Standard Error Format explained below. For example, {name} will be replaced by Foo if format is passed in as {name='Foo'}.

To raise an error from (non-Frame object receiving) inner function:
 * Standard Error Format (SEF)

The type field should be an existing Error Signature. The format field should be key-value pairs fed to the replacement fields.

These functions should be marked with .

The top-level caller, the one receiving a Frame object from the wikitext world, should handle the error.
 * Standard (Top-level) Handling Format (SHF)

These functions should be marked with .


 * Other Notes
 * Normally, the top-level handler (SHF) function is not called by other functions. If it is called further within the Lua world, the new caller will have no idea whether the response is successful. This is no problem if the result is placed on screen without further processing. It may produce side effect if the data is further processed.
 * To prevent side effects, it is beneficial to have a system of all SafeResponse exception raisers and handlers, or a system without any SafeResponse features, not a mix of both systems.