1# A dummy extension that installs an hgweb command that throws an Exception.
2
3from __future__ import absolute_import
4
5from mercurial.hgweb import webcommands
6
7
8def raiseerror(web):
9    '''Dummy web command that raises an uncaught Exception.'''
10
11    # Simulate an error after partial response.
12    if b'partialresponse' in web.req.qsparams:
13        web.res.status = b'200 Script output follows'
14        web.res.headers[b'Content-Type'] = b'text/plain'
15        web.res.setbodywillwrite()
16        list(web.res.sendresponse())
17        web.res.getbodyfile().write(b'partial content\n')
18
19    raise AttributeError('I am an uncaught error!')
20
21
22def extsetup(ui):
23    setattr(webcommands, 'raiseerror', raiseerror)
24    webcommands.__all__.append(b'raiseerror')
25