Patchwork chgserver: catch Abort while parsing early args to shut down cleanly

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 7, 2018, 2:32 p.m.
Message ID <61cd3abbe6713d4e515e.1538922726@mimosa>
Download mbox | patch
Permalink /patch/35532/
State New
Headers show

Comments

Yuya Nishihara - Oct. 7, 2018, 2:32 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1538901325 -32400
#      Sun Oct 07 17:35:25 2018 +0900
# Node ID 61cd3abbe6713d4e515e1630a32e8d6f96e41c2c
# Parent  d7cc5ddafd50c980258b31be165c834da1fa2abe
chgserver: catch Abort while parsing early args to shut down cleanly

_loadnewui() calls dispatcher functions, which may raise Abort if unparsable
arguments are passed in. The server should catch such errors and translate
them to the "exit 255" instruction so the client can finish the IPC session
cleanly.

Spotted while porting the chg client to Rust.

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -425,6 +425,13 @@  class chgcmdserver(commandserver.server)
             self.ui.flush()
             self.cresult.write('exit 255')
             return
+        except error.Abort as inst:
+            self.ui.error(_("abort: %s\n") % inst)
+            if inst.hint:
+                self.ui.error(_("(%s)\n") % inst.hint)
+            self.ui.flush()
+            self.cresult.write('exit 255')
+            return
         newhash = hashstate.fromui(lui, self.hashstate.mtimepaths)
         insts = []
         if newhash.mtimehash != self.hashstate.mtimehash: