From 8d40122372e31052f10e68005c989c5f067916aa Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Fri, 11 May 2018 23:40:26 +0200
Subject: Display unexpected messages, too
---
json-rpc-shell.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/json-rpc-shell.c b/json-rpc-shell.c
index 77a9fa9..eda958b 100644
--- a/json-rpc-shell.c
+++ b/json-rpc-shell.c
@@ -1917,6 +1917,9 @@ backend_ws_on_control_frame
return true;
}
+static int normalize_whitespace (int c) { return isspace_ascii (c) ? ' ' : c; }
+
+/// Caller guarantees that data[len] is a NUL byte (because of iconv_xstrdup())
static bool
backend_ws_on_message (struct ws_context *self,
enum ws_opcode type, const void *data, size_t len)
@@ -1926,7 +1929,12 @@ backend_ws_on_message (struct ws_context *self,
if (!self->waiting_for_event || !self->response_buffer)
{
- print_warning ("unexpected message received");
+ char *s = iconv_xstrdup (self->ctx->term_from_utf8,
+ (char *) data, len + 1 /* null byte */, NULL);
+ // Does not affect JSON and ensures the message is printed out okay
+ cstr_transform (s, normalize_whitespace);
+ print_warning ("unexpected message received: %s", s);
+ free (s);
return true;
}
--
cgit v1.2.3-70-g09d2