Comment 9 for bug 413174

Revision history for this message
Benji York (benji) wrote :

> I was hoping for something simple. We know every AssertError is meant
> to be seen by an engineer. We know for Launchpad the engineer can look
> at the oops or the log of a test. For external developers we want to
> adapt the AssertionError to a Response that equates/creates a HTTP 500
> and the assertion message is included.

I think that last sentence is where we diverge. Assertions are for the
people developing the code, not using it. Any time an assertion fires
it indicates a mistake on the part of the programmer(s) that put it in,
not the user (even if the user is another programmer on the other side
of an API).

In the case of OOPS-1694EB1486 the exception generated should not have
been an assertion error because there was no mistake on the part of the
LP developer. The mistake was made by the caller of the function
because that function can not be called on a project that is linked to
source packages.

Similarly, the exception in OOPS-1318S626 should not be an
AssertionError because there was no mistake on the part of the LP
programmer, but on the part of the API user.

I'll change both the assertions in question to instead raise exceptions
(probably ValueError or RuntimeError) with an interface added (via a
wrapper as described in comment #7) that lazr.restful knows to translate
into an HTTP error.