wireprotov2: change command response protocol to include a leading map
The error handling mechanism for the new wire protocol isn't very
well-defined. This commit takes us a step in the right direction
by introducing a leading CBOR map for command responses. This map
will contain an overall result of the command.
Currently, the map indicates whether the command was overall
successful or if an error occurred. And if an error occurred, that
error is present in the map.
There is still a dedicated error frame. My intent is to use that
for protocol-level errors and for errors that are encountered after
the initial response frame has been sent. This will be clarified in a
later commit.
Differential Revision: https://phab.mercurial-scm.org/D3385
# A dummy extension that installs an hgweb command that throws an Exception.
from __future__ import absolute_import
from mercurial.hgweb import (
webcommands,
)
def raiseerror(web):
'''Dummy web command that raises an uncaught Exception.'''
# Simulate an error after partial response.
if 'partialresponse' in web.req.qsparams:
web.res.status = b'200 Script output follows'
web.res.headers[b'Content-Type'] = b'text/plain'
web.res.setbodywillwrite()
list(web.res.sendresponse())
web.res.getbodyfile().write(b'partial content\n')
raise AttributeError('I am an uncaught error!')
def extsetup(ui):
setattr(webcommands, 'raiseerror', raiseerror)
webcommands.__all__.append('raiseerror')