Forráskód Böngészése

Document node.setonerror()

Fixes #3381
Marcel Stör 3 éve
szülő
commit
8943b31f2c
1 módosított fájl, 26 hozzáadás és 1 törlés
  1. 26 1
      docs/modules/node.md

+ 26 - 1
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.