Patchwork [04,of,12,stable] bundle2: use a more specific UnknownPartError when no handler is found

login
register
mail settings
Submitter Pierre-Yves David
Date April 22, 2014, 8:10 p.m.
Message ID <574682bc8678be8e4260.1398197448@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4422/
State Accepted
Commit 372f4772f7a00e9508b39df7bf94d7f060bb516c
Headers show

Comments

Pierre-Yves David - April 22, 2014, 8:10 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1398134560 25200
#      Mon Apr 21 19:42:40 2014 -0700
# Branch stable
# Node ID 574682bc8678be8e42609396f418448a5942c1ce
# Parent  d2ed7a2bc8301f7a7e5e1c34175950206da27cc6
bundle2: use a more specific UnknownPartError when no handler is found

KeyError is very generic, we need something more specific for proper error
handling.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -168,10 +168,14 @@  def _makefpartparamsizes(nbparams):
     The number parameters is variable so we need to build that format
     dynamically.
     """
     return '>'+('BB'*nbparams)
 
+class UnknownPartError(KeyError):
+    """error raise when no handler is found for a Mandatory part"""
+    pass
+
 parthandlermapping = {}
 
 def parthandler(parttype):
     """decorator that register a function as a bundle2 part handler
 
@@ -295,11 +299,11 @@  def processbundle(repo, unbundler, trans
                 op.ui.debug('found a handler for part %r\n' % parttype)
             except KeyError:
                 if key != parttype: # mandatory parts
                     # todo:
                     # - use a more precise exception
-                    raise
+                    raise UnknownPartError(key)
                 op.ui.debug('ignoring unknown advisory part %r\n' % key)
                 # consuming the part
                 part.read()
                 continue