guard exceptions and return HTTP 500 with str() of caught exception (or a better message if/when possible)
First of all -- THANK YOU for the metasnap. It is a "rare-to-be-used" tool but of unique need/purpose. I do expect to use it on various occasions, most likely in conjunction with nd_freeze we provide in neurodebian-freeze package.
While trying on a sample query got following:
$> curl --silent 'https://metasnap.debian.net/cgi-bin/api?archive=debian&pkgs=python-mvpa&arch=amd64&comp=main'
<body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#6622aa">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>AssertionError</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial">Python 3.7.3: /usr/bin/python3<br>Wed Apr 21 20:00:52 2021</font></td></tr></table>
<p>A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.</p>
<table width="100%" cellspacing=0 cellpadding=0 border=0>
<tr><td bgcolor="#d8bbff"><big> </big><a href="file:///var/www/cgi-bin/api">/var/www/cgi-bin/api</a> in <strong><module></strong>()</td></tr>
<tr><td><font color="#909090"><tt> <small> 161</small> keys, values = zip(*qs)<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt> <small> 162</small> <br>
</tt></font></td></tr>
<tr><td bgcolor="#ffccee"><tt>=><small> 163</small> assert keys in [<br>
</tt></td></tr>
<tr><td bgcolor="#ffccee"><tt>=><small> 164</small> ("timestamps",),<br>
</tt></td></tr>
<tr><td bgcolor="#ffccee"><tt>=><small> 165</small> ("archive", "timestamp", "suite", "comp", "pkg", "arch"),<br>
</tt></td></tr>
<tr><td><small><font color="#909090"><strong>keys</strong> = ('archive', 'pkgs', 'arch', 'comp')</font></small></td></tr></table><p><strong>AssertionError</strong>:
<br><tt><small> </small> </tt>args =
()
<br><tt><small> </small> </tt>with_traceback =
<built-in method with_traceback of AssertionError object>
<!-- The above is a description of an error in a Python program, formatted
for a Web browser because the 'cgitb' module was enabled. In case you
are not reading this in a Web browser, here is the original traceback:
Traceback (most recent call last):
File "/var/www/cgi-bin/api", line 163, in <module>
assert keys in [
AssertionError
-->
IMHO
- since
/api
end point, I do not expect HTML but structured record, and some standard HTTP return codes. - should not leak deployment (paths) /code details