poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED 2/2] poked: Add OUTCMD_ERR to report errors


From: Mohammad-Reza Nabipoor
Subject: [COMMITTED 2/2] poked: Add OUTCMD_ERR to report errors
Date: Fri, 11 Mar 2022 19:00:46 +0330

2022-03-11  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * poked/poked.c (OUTCMD_ERR): New macro.
        * poked/poked.pk (__err_send): New function to report errors.
        (poked_ehandler): Change default error handler to use `__err_send`
        instead of `print`.
---
 ChangeLog      |  7 +++++++
 poked/poked.c  |  1 +
 poked/poked.pk | 51 ++++++++++++++++++++++++++++++++------------------
 3 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c38a681e..7d238475 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-03-11  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * poked/poked.c (OUTCMD_ERR): New macro.
+       * poked/poked.pk (__err_send): New function to report errors.
+       (poked_ehandler): Change default error handler to use `__err_send`
+       instead of `print`.
+
 2022-03-11  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
 
        * poked/usock.h (usock_out): Change the function prototype: re-order
diff --git a/poked/poked.c b/poked/poked.c
index 0f18ce0a..91bbf860 100644
--- a/poked/poked.c
+++ b/poked/poked.c
@@ -45,6 +45,7 @@ static void poked_free (void);
 #define OUTCMD_CLS_BEGIN 4
 #define OUTCMD_CLS_END 5
 #define OUTCMD_EVAL 6
+#define OUTCMD_ERR 7
 
 #define VUKIND_CLEAR 1
 #define VUKIND_APPEND 2
diff --git a/poked/poked.pk b/poked/poked.pk
index 0fe6daf3..0fb50275 100644
--- a/poked/poked.pk
+++ b/poked/poked.pk
@@ -27,24 +27,6 @@ var __poked_exit_p = 0;
 fun poked_restart = void: { __poked_restart_p = 1; exit; }
 fun poked_exit = void: { __poked_exit_p = 1; exit; }
 fun poked_defer = void: {}
-fun poked_ehandler = (Exception exception) void:
-  {
-    if (exception.code != EC_exit && exception.code != EC_signal)
-      {
-        print ("unhandled "
-               + (exception.name == "" ? "unknown" : exception.name)
-               + " exception\n");
-
-        if (exception.location != "" || exception.msg != "")
-          {
-            if (exception.location != "")
-              print (exception.location + " ");
-            print (exception.msg + "\n");
-          }
-      }
-    if (exception.code == EC_exit)
-      __poked_exit_p = 1;
-  }
 
 //--- send over channels
 
@@ -68,6 +50,39 @@ fun chan_send = (uint<7> chan, byte[] data) void:
     __chan_send_p = 1;
   }
 
+//--- default exception handler
+
+/* NOTE Due to current implementation limitation, you can call this
+   function only once in each iteration.  */
+fun __err_send = (string s) void:
+  {
+    var c = byte[s'length] ();
+
+    stoca (s, c);
+    chan_send (/*USOCK_CHAN_OUT_OUT*/ 1, [/*OUTCMD_ERR*/ 7UB] + c);
+  }
+
+fun poked_ehandler = (Exception exception) void:
+  {
+    var msg = "unhandled ";
+
+    if (exception.code != EC_exit && exception.code != EC_signal)
+      {
+        msg += (exception.name == "" ? "unknown" : exception.name)
+               + " exception\n";
+
+        if (exception.location != "" || exception.msg != "")
+          {
+            if (exception.location != "")
+              msg += exception.location + " ";
+            msg += exception.msg;
+          }
+      }
+    __err_send (msg);
+    if (exception.code == EC_exit)
+      __poked_exit_p = 1;
+  }
+
 //--- vu
 
 var __dots = [[0L#N,0L#N]];
-- 
2.35.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]