Skip to content

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>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<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>&nbsp;</big><a href="file:///var/www/cgi-bin/api">/var/www/cgi-bin/api</a> in <strong>&lt;module&gt;</strong>()</td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;161</small>&nbsp;keys,&nbsp;values&nbsp;=&nbsp;zip(*qs)<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;162</small>&nbsp;<br>
</tt></font></td></tr>
<tr><td bgcolor="#ffccee"><tt>=&gt;<small>&nbsp;&nbsp;163</small>&nbsp;assert&nbsp;keys&nbsp;in&nbsp;[<br>
</tt></td></tr>
<tr><td bgcolor="#ffccee"><tt>=&gt;<small>&nbsp;&nbsp;164</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;("timestamps",),<br>
</tt></td></tr>
<tr><td bgcolor="#ffccee"><tt>=&gt;<small>&nbsp;&nbsp;165</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;("archive",&nbsp;"timestamp",&nbsp;"suite",&nbsp;"comp",&nbsp;"pkg",&nbsp;"arch"),<br>
</tt></td></tr>
<tr><td><small><font color="#909090"><strong>keys</strong>&nbsp;= ('archive', 'pkgs', 'arch', 'comp')</font></small></td></tr></table><p><strong>AssertionError</strong>: 
<br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>args&nbsp;=
()
<br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>with_traceback&nbsp;=
&lt;built-in method with_traceback of AssertionError object&gt;


<!-- 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 &lt;module&gt;
    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