the-kenny / weechat.el

Chat via weechat's relay protocol in Emacs
177 stars 41 forks source link

weechat-matrix color code #89

Open malb opened 4 years ago

malb commented 4 years ago

I'm seeing

ELISP> (weechat-handle-color-codes "\031F02\031B00Test\031\034\031")
*** Eval error ***  Args out of range: 

where "\031F02\031B00Test\031\034\031" is produced when I try to post using weechat.el to a matrix channel via weechat-matrix

rrix commented 4 years ago

tl;dr: /set matrix.network.print_unconfirmed_messages 0

I am noodling on this right now, some thoughts: weechat dev docs show that this string is invalid, there is an extra character tacked on to the end -- that last \031shouldn't be there. I've been looking in weechat-matrix source code which generates this and it seems sound -- it's calling in to core weechat code which I believe gets to here. I haven't validated any of these assumptions of following the code fwiw.

It looks like these messages are being misformed on the weechat-matrix side. If you enable debug on error and attempt to send a message, you can examine the data all the way back from the Process Filter which is pulling the bits out of weechat's relay, and find that it also has the extra ^Y. The weechat-matrix folks mention that there is a major rewrite in progress to move it to Rust in poljar/weechat-matrix#179 which may inadvertantly address this, but someone should probably write an error report on weechat-matrix side. I think the failure is somewhere in this which strips the colors of the sent message to make it appear dark gray: here I don't feel like attaching debugger or printf-diving on the weechat plugin side, but you can turn off that code path /set matrix.network.print_unconfirmed_messages 0

As an aside: i think it's safe to assume that last character is simply invalid, but I think something else is also happening in the color parsing code, weechat relay-log has messages Broken color code (in ?B '^YB00^YF02hi^Y^C^Y' 1) which is being logged just before the error condition, in processing the first color code, 'B00', but weechat--match-color-code doesn't behave the way i expect it to, so following the code left me confused about that. (setq weechat-strip-formatting t) leaves a single "^Y" in messages, so that doesn't help.

malb commented 4 years ago

Thanks!

phil-s commented 3 years ago

Even with /set matrix.network.print_unconfirmed_messages 0, I'm still seeing the occasional

(weechat-handle-color-codes "\31")

Which fails when attempting to get the next character after that one, as there isn't one. I'm trying the following change to that function:

@@ -289,10 +289,11 @@
       (cl-case (aref str i)
         ((?\x19) ;; STD|EXT|?F((A)STD|(A)EXT)|?B(STD|EXT)|?\x1C|?*...|?b...
          (let ((old-face face)
-               (next (aref str (1+ i))))
+               (next (and (> len (1+ i)) (aref str (1+ i)))))
            (setq face nil)
            (setq i (1+ i))
            (cond
+            ((not next))
             ((and (<= ?0 next) (<= next ?9)) ;; STD
              (let ((match-data (weechat--match-color-code 'std str i)))
                (when match-data