changeset 28512:b957b4c6cad8

chg: provide early exception to user See the previous patch for details. Since the socket will be closed by the server, handleresponse() will never return: Traceback (most recent call last): ... chg: abort: failed to read channel
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 Mar 2016 22:17:30 +0900
parents ff5f923fca3c
children 859af6e78368
files contrib/chg/hgclient.c
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/hgclient.c	Sat Mar 12 22:03:30 2016 +0900
+++ b/contrib/chg/hgclient.c	Sat Mar 12 22:17:30 2016 +0900
@@ -311,9 +311,16 @@
 {
 	readchannel(hgc);
 	context_t *ctx = &hgc->ctx;
-	if (ctx->ch != 'o')
-		abortmsg("unexpected channel of hello message (ch = %c)",
-			 ctx->ch);
+	if (ctx->ch != 'o') {
+		char ch = ctx->ch;
+		if (ch == 'e') {
+			/* write early error and will exit */
+			fwrite(ctx->data, sizeof(ctx->data[0]), ctx->datasize,
+			       stderr);
+			handleresponse(hgc);
+		}
+		abortmsg("unexpected channel of hello message (ch = %c)", ch);
+	}
 	enlargecontext(ctx, ctx->datasize + 1);
 	ctx->data[ctx->datasize] = '\0';
 	debugmsg("hello received: %s (size = %zu)", ctx->data, ctx->datasize);