actors: Fix serialize-message to not use address->string
[8sync.git] / 8sync / systems / actors.scm
index bd164be2c26199e1f2fa1a6730085dddd162e777..8bff1d4365795b11c4980178cb342ef5f6a3b1a2 100644 (file)
             reply-message reply-message-wait
 
             ez-run-hive
-            hive-bootstrap-message))
+            hive-bootstrap-message
+
+            serialize-message write-message
+            serialize-message-pretty pprint-message
+            read-message read-message-from-string))
 
 ;; For ids
 (define %random-state
@@ -461,13 +465,22 @@ Instead, actors should call create-actor."
 ;;   change), and using existing tooling (though adding new tooling
 ;;   would be negligible in implementation effort.)
 
-(define* (message-ref message key #:optional dflt)
+;; This cons cell is immutable and unique (for eq? tests)
+(define %nothing-provided (cons 'nothing 'provided))
+
+(define* (message-ref message key #:optional (dflt %nothing-provided))
   "Extract KEY from body of MESSAGE.
 
-Optionally set default with [DFLT]"
+Optionally set default with [DFLT]
+If key not found and DFLT not provided, throw an error."
   (let ((result (assoc key (message-body message))))
     (if result (cdr result)
-        dflt)))
+        (if (eq? dflt %nothing-provided)
+            (throw 'message-missing-key
+                   "Message body does not contain key and no default provided"
+                   #:key key
+                   #:message message)
+            dflt))))
 
 
 (define (kwarg-list-to-alist args)
@@ -568,8 +581,8 @@ an integer."
   "Serialize a message for read/write"
   (list
    (message-id message)
-   (address->string (message-to message))
-   (address->string (message-from message))
+   (message-to message)
+   (message-from message)
    (message-action message)
    (message-body message)
    (message-in-reply-to message)