Patchwork [7,of,7] bundle2: use ProgrammingError to report bad use of addparam()

login
register
mail settings
Submitter Yuya Nishihara
Date July 9, 2018, 1:24 p.m.
Message ID <f64791ccde76f9e1cf8f.1531142677@mimosa>
Download mbox | patch
Permalink /patch/32705/
State Accepted
Headers show

Comments

Yuya Nishihara - July 9, 2018, 1:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1531045458 -32400
#      Sun Jul 08 19:24:18 2018 +0900
# Node ID f64791ccde76f9e1cf8f44a80a000d8084ea0a8c
# Parent  9a7d1a087b1807a06b2e051725c69e0e0275c001
bundle2: use ProgrammingError to report bad use of addparam()

This allows us to embed error message in bytes.
Augie Fackler - July 9, 2018, 2:11 p.m.
> On Jul 9, 2018, at 09:24, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1531045458 -32400
> #      Sun Jul 08 19:24:18 2018 +0900
> # Node ID f64791ccde76f9e1cf8f44a80a000d8084ea0a8c
> # Parent  9a7d1a087b1807a06b2e051725c69e0e0275c001
> bundle2: use ProgrammingError to report bad use of addparam()

Queued, these, many thanks.

Patch

diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist
--- a/contrib/python3-whitelist
+++ b/contrib/python3-whitelist
@@ -38,6 +38,7 @@  test-bundle-type.t
 test-bundle-vs-outgoing.t
 test-bundle.t
 test-bundle2-exchange.t
+test-bundle2-format.t
 test-bundle2-multiple-changegroups.t
 test-bundle2-pushback.t
 test-cappedreader.py
diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -628,9 +628,10 @@  class bundle20(object):
     def addparam(self, name, value=None):
         """add a stream level parameter"""
         if not name:
-            raise ValueError(r'empty parameter name')
+            raise error.ProgrammingError(b'empty parameter name')
         if name[0:1] not in pycompat.bytestr(string.ascii_letters):
-            raise ValueError(r'non letter first character: %s' % name)
+            raise error.ProgrammingError(b'non letter first character: %s'
+                                         % name)
         self._params.append((name, value))
 
     def addpart(self, part):
diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -91,8 +91,8 @@  Create an extension to test bundle2 API
   >         p = p.split(b'=', 1)
   >         try:
   >             bundler.addparam(*p)
-  >         except ValueError as exc:
-  >             raise error.Abort('%s' % exc)
+  >         except error.ProgrammingError as exc:
+  >             raise error.Abort(b'%s' % exc)
   > 
   >     if opts['compress']:
   >         bundler.setcompression(opts['compress'])