dictionary-overlay icon indicating copy to clipboard operation
dictionary-overlay copied to clipboard

websocket parse json error

Open ginqi7 opened this issue 2 years ago • 4 comments

image

Sometimes there will be an error like that:

⛔ Error (websocket): in callback `on-message': could not parse JSON stream: "unable to decode byte 0xc3", "", 1, 0, 0

It won't affect this tool's usability, but it bothers me.

ginqi7 avatar Nov 25 '22 15:11 ginqi7

would it help to wrap related code in (with-no-warnings ...) or (ignore-errors ...) somewhere. i haven't look into this issue yet.

qingshuizheng avatar Nov 27 '22 00:11 qingshuizheng

or, the error buffer could be managed like elfeed-log buffer: it never shows up, but retrievable by M-x switch-to-buffer RET elfeed-log RET

qingshuizheng avatar Nov 27 '22 00:11 qingshuizheng

So, basically i just ignore errors here, finally manage to calm it down. Don't know what the consequences would be, perhaps some words are not saved to the .txt file when err out? Anyway, i'm happy.

(defun websocket-bridge-message-handler (_websocket frame)
  "Message handler for given FRAME."
  (ignore-errors         ;;; <------ What i did.
    (let* ((info (json-parse-string (websocket-frame-text frame)))
           (info-type (gethash "type" info nil)))
      (pcase info-type
        ("client-app-name"
         (set
          (intern
           (format "websocket-bridge-client-%s"
                   (gethash "content" info nil)))
          _websocket))
        ("show-message" (message (gethash "content" info nil)))
        ("eval-code" (eval (read (gethash "content" info nil))))
        ("fetch-var"
         (websocket-send-text _websocket
                              (json-encode
                               (eval
                                (read (gethash "content" info nil))))))))))

qingshuizheng avatar Nov 29 '22 12:11 qingshuizheng

Maybe ignoring the json-parse-string's error is better.

If you ignore too much, it will hide the import message when there is an actual run error.

I will wait to find the real error reason.

ginqi7 avatar Nov 29 '22 13:11 ginqi7