# HG changeset patch # User Jun Wu # Date 1457959955 0 # Node ID 3bf2892f685f3e240768e2f3b109f4a61a7839d3 # Parent 491eabd0df79ac5f9a0719cd1c26e480212457ba chgserver: handle ParseError during validate Currently the validate command in chgserver expects config can be loaded without issues but the config can be broken and chg will print a stacktrace instead of the parsing error, if a chg server is already running. This patch adds a handler for ParseError in validate and a new instruction "exit" to make the client exit without abortmsg. A test is also added to make sure it will behave as expected. diff -r 491eabd0df79 -r 3bf2892f685f contrib/chg/chg.c --- a/contrib/chg/chg.c Mon Mar 14 12:32:09 2016 +0000 +++ b/contrib/chg/chg.c Mon Mar 14 12:52:35 2016 +0000 @@ -460,6 +460,11 @@ "%s", *pinst + 9); if (r < 0 || r >= (int)sizeof(opts->redirectsockname)) abortmsg("redirect path is too long (%d)", r); + } else if (strncmp(*pinst, "exit ", 5) == 0) { + int n = 0; + if (sscanf(*pinst + 5, "%d", &n) != 1) + abortmsg("cannot read the exit code"); + exit(n); } else { abortmsg("unknown instruction: %s", *pinst); } diff -r 491eabd0df79 -r 3bf2892f685f hgext/chgserver.py --- a/hgext/chgserver.py Mon Mar 14 12:32:09 2016 +0000 +++ b/hgext/chgserver.py Mon Mar 14 12:52:35 2016 +0000 @@ -429,9 +429,17 @@ outdated server. - "redirect $path", the client should try to connect to another server instead. + - "exit $n", the client should exit directly with code n. + This may happen if we cannot parse the config. """ args = self._readlist() - self.ui = _renewui(self.ui, args) + try: + self.ui = _renewui(self.ui, args) + except error.ParseError as inst: + dispatch._formatparse(self.ui.warn, inst) + self.ui.flush() + self.cresult.write('exit 255') + return newhash = hashstate.fromui(self.ui, self.hashstate.mtimepaths) insts = [] if newhash.mtimehash != self.hashstate.mtimehash: diff -r 491eabd0df79 -r 3bf2892f685f tests/test-chg.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-chg.t Mon Mar 14 12:52:35 2016 +0000 @@ -0,0 +1,12 @@ +init repo + + $ hg init foo + $ cd foo + +ill-formed config + + $ hg status + $ echo '=brokenconfig' >> $HGRCPATH + $ hg status + hg: parse error at * (glob) + [255]