Prevent a channel from stopping on errors
Verified
Added by iNTERFACEWARE
A very simple way to run all your code in protected mode with pcall() and log errors instead of stopping
Source Code
local function ProtectedMain(Data) -- replace with real processing and real error handling error("Bang!") return "Some", "Data" end function main(Data) local Success, Err = pcall(ProtectedMain, "DataIn") if not Success then iguana.logError("Skipping error: "..Err) end end
Description
A very simple way to run all your code in protected mode with pcall() and log errors instead of stopping
Usage Details
This code uses pcall()
to run all your code in protected mode, and log errors instead of stopping. The principle is very simple we simply replace main()
with protectedMain()
. Then we call pcall()
to run protectedMain()
, from main()
, and trap and log all errors that occur.
Note: The protectedMain()
only contains dummy code to raise an error.
How to use the code:
- Paste the code into a script
- Inspect the code, annotations and logs to see how it works
- To protect an existing
main()
is very simple:- Rename (existing)
main()
toprotectedMain()
- Use the
main()
from the above code - You may want to adapt the error handling in
main()
- Rename (existing)
More Information
Added by iNTERFACEWARE
Demonstrates the use of conn:execute{} to call a stored procedure.
Added by iNTERFACEWARE
Demonstrates how to use conn:merge{} with a table that has an auto-incrementing Id column.
Added by iNTERFACEWARE
This script automatically creates a SQLite database and then generates the tables specified in a VMD.
Added by iNTERFACEWARE
Create a custom ACK by using a script in an LLP Listener component
Added by iNTERFACEWARE
Retries a a custom ACK using the retry.lua module
Added by iNTERFACEWARE
Query a database to identify patient in incoming HL7 messages. If a patient is not found return an ACK with a "Patient does not exist" message.
Added by iNTERFACEWARE
This function formats phone numbers nicely with the area code in brackets.
Added by iNTERFACEWARE
Use smtp.send() to send an email from your Lua code.
Added by iNTERFACEWARE
Simple functions to strip or add leading zeros
Added by iNTERFACEWARE
How to use transactions and conn:begin{}, conn:execute{} and conn:commit{} to insert data into a database in a specific order.
Added by iNTERFACEWARE
How to process a batch of HL7 messages by removing the batch header and splitting it into separate messages.
Added by iNTERFACEWARE
Retry an ODBC query to a MySQL DB when an error occurs, can be adapted for retrying LLP etc.
Added by iNTERFACEWARE
Format specified HL7 message fields in a tab delimited string and push the string to the queue for further processing
Added by iNTERFACEWARE
How to normalize X12 delimiters for processing in Iguana scripts, they can be reverted after processing if needed
Added by iNTERFACEWARE
How to format a report as a single NTE or OBX segment with repeating field or using multiple NTE segments, one for each line of the report
Added by iNTERFACEWARE
How to encode binary files as base 64 text, then embed them as OBX-5 segment repeats
Added by iNTERFACEWARE
This function calculates age from DOB, it returns years, months and partial years (i.e., 17, 3, 17.296272).
Added by iNTERFACEWARE
This code checks EDI (XML) data for some common errors, you can use this approach for pre-processing messages to clean them up