From 0e0a03d6aeb65c2dd59994e0e0e4b46655718dac Mon Sep 17 00:00:00 2001
From: Thierry Fournier <thierry.fournier@ozon.io>
Date: Sat, 15 Aug 2020 14:35:51 +0200
Subject: [PATCH] MINOR: hlua: Add error message relative to the Channel
 manipulation and HTTP mode

When the developper try to manipulate HAProxy channels in HTTP mode,
an error throws without explanation. This patch adds an explanation.
---
 src/hlua.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/hlua.c b/src/hlua.c
index 36a84ab..956ca75 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2747,8 +2747,10 @@ __LJMP static int hlua_channel_dup_yield(lua_State *L, int status, lua_KContext
 
 	chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-	if (chn_strm(chn)->be->mode == PR_MODE_HTTP)
+	if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+		lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
 		WILL_LJMP(lua_error(L));
+	}
 
 	if (_hlua_channel_dup(chn, L) == 0)
 		MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_dup_yield, TICK_ETERNITY, 0));
@@ -2775,8 +2777,10 @@ __LJMP static int hlua_channel_get_yield(lua_State *L, int status, lua_KContext
 
 	chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-	if (chn_strm(chn)->be->mode == PR_MODE_HTTP)
+	if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+		lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
 		WILL_LJMP(lua_error(L));
+	}
 
 	ret = _hlua_channel_dup(chn, L);
 	if (unlikely(ret == 0))
@@ -2815,8 +2819,10 @@ __LJMP static int hlua_channel_getline_yield(lua_State *L, int status, lua_KCont
 
 	chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-	if (chn_strm(chn)->be->mode == PR_MODE_HTTP)
+	if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+		lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
 		WILL_LJMP(lua_error(L));
+	}
 
 	ret = ci_getline_nc(chn, &blk1, &len1, &blk2, &len2);
 	if (ret == 0)
@@ -2863,8 +2869,10 @@ __LJMP static int hlua_channel_append_yield(lua_State *L, int status, lua_KConte
 	int ret;
 	int max;
 
-	if (chn_strm(chn)->be->mode == PR_MODE_HTTP)
+	if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+		lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
 		WILL_LJMP(lua_error(L));
+	}
 
 	/* Check if the buffer is available because HAProxy doesn't allocate
 	 * the request buffer if its not required.
@@ -2935,8 +2943,10 @@ __LJMP static int hlua_channel_set(lua_State *L)
 	chn = MAY_LJMP(hlua_checkchannel(L, 1));
 	lua_pushinteger(L, 0);
 
-	if (chn_strm(chn)->be->mode == PR_MODE_HTTP)
+	if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+		lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
 		WILL_LJMP(lua_error(L));
+	}
 
 	b_set_data(&chn->buf, co_data(chn));
 
@@ -2957,8 +2967,10 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
 	int max;
 	struct hlua *hlua = hlua_gethlua(L);
 
-	if (chn_strm(chn)->be->mode == PR_MODE_HTTP)
+	if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+		lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
 		WILL_LJMP(lua_error(L));
+	}
 
 	if (unlikely(channel_output_closed(chn))) {
 		lua_pushinteger(L, -1);
@@ -3061,8 +3073,10 @@ __LJMP static int hlua_channel_forward_yield(lua_State *L, int status, lua_KCont
 
 	chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-	if (chn_strm(chn)->be->mode == PR_MODE_HTTP)
+	if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+		lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
 		WILL_LJMP(lua_error(L));
+	}
 
 	len = MAY_LJMP(luaL_checkinteger(L, 2));
 	l = MAY_LJMP(luaL_checkinteger(L, -1));
-- 
2.1.4

