Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/bundle2.py @ 21179:372f4772f7a0 stable
bundle2: use a more specific UnknownPartError when no handler is found
KeyError is very generic, we need something more specific for proper error
handling.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 21 Apr 2014 19:42:40 -0700 |
parents | 952af771bc17 |
children | 4345274adc4b |
comparison
equal
deleted
inserted
replaced
21178:9a813e703172 | 21179:372f4772f7a0 |
---|---|
167 | 167 |
168 The number parameters is variable so we need to build that format | 168 The number parameters is variable so we need to build that format |
169 dynamically. | 169 dynamically. |
170 """ | 170 """ |
171 return '>'+('BB'*nbparams) | 171 return '>'+('BB'*nbparams) |
172 | |
173 class UnknownPartError(KeyError): | |
174 """error raised when no handler is found for a Mandatory part""" | |
175 pass | |
172 | 176 |
173 parthandlermapping = {} | 177 parthandlermapping = {} |
174 | 178 |
175 def parthandler(parttype): | 179 def parthandler(parttype): |
176 """decorator that register a function as a bundle2 part handler | 180 """decorator that register a function as a bundle2 part handler |
295 op.ui.debug('found a handler for part %r\n' % parttype) | 299 op.ui.debug('found a handler for part %r\n' % parttype) |
296 except KeyError: | 300 except KeyError: |
297 if key != parttype: # mandatory parts | 301 if key != parttype: # mandatory parts |
298 # todo: | 302 # todo: |
299 # - use a more precise exception | 303 # - use a more precise exception |
300 raise | 304 raise UnknownPartError(key) |
301 op.ui.debug('ignoring unknown advisory part %r\n' % key) | 305 op.ui.debug('ignoring unknown advisory part %r\n' % key) |
302 # consuming the part | 306 # consuming the part |
303 part.read() | 307 part.read() |
304 continue | 308 continue |
305 | 309 |