From 34ad3370bd4fba3d5487abfba778cbfe3d585627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Fri, 12 Feb 2021 21:14:17 +0100 Subject: [PATCH] Document node.setonerror() Fixes #3381 --- docs/modules/node.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/modules/node.md b/docs/modules/node.md index 8abae693..f1911fbb 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -462,7 +462,6 @@ node.restore() node.restart() -- ensure the restored settings take effect ``` - ## node.setcpufreq() Change the working CPU Frequency. @@ -481,6 +480,32 @@ target CPU frequency (number) node.setcpufreq(node.CPU80MHZ) ``` +## node.setonerror() + +Use this to override the default "always restart" action if wanted; for example to write an error to a logfile or to a network syslog before restarting. + +!!! attention + + It is strongly advised to ensure that the callback ends with a restart. Something has gone quite wrong and it is probably not safe to just wait for the next event (e.g., timer tick) and hope everything works out. + +#### Syntax +`node.setonerror(function)` + +#### Parameters +`function` a callback function to be executed when an error occurs, gets the error string as an argument, remember to **trigger a restart** at the end of the callback + +#### Returns +`nil` + +#### Example +```lua +node.setonerror(function(s) + print("Error: "..s) + node.restart() + end) +``` + + ## node.setpartitiontable() Sets the current LFS and / or SPIFFS partition information.