mountetna / magma

Data server with friendly data loaders
GNU General Public License v2.0
5 stars 2 forks source link

Graft fix matrix slice #121

Closed graft closed 4 years ago

graft commented 4 years ago

While poking around in Magma::MatrixAttribute to try and figure out #119, I discovered that the '::slice' verb to the Magma::MatrixPredicate behaves poorly (i.e., 500s) with invalid arguments. Normally the argument to slice should be an array of strings mapping to the column names associated with the matrix attribute (e.g. [ ..., 'matrix', '::slice', [ 'GENE1', 'GENE2' ] ]). The list of valid column names is currently shoved into the match parameter of the matrix attribute; if the arguments to the column name are invalid, Magma errors when trying to extract the slice. Instead, it should return a 422 to the user with some instructions on what to fix.

To support this, this PR does two things: 1) A validation interface is added to Magma::Verb. This allows the verb to examine the arguments given to it when instantiated and check whether they are invalid. This new interface is only in use in the MatrixPredicate, although it could probably be made use of in other places (e.g. the RecordPredicate), perhaps everywhere we do any argument checking for any predicate.

2) The error needs to raise back to the user and give a 422; to facilitate this I replaced raising of ArgumentError (which was ambiguous as to who caused the error) with a QuestionError class which is caught in the controller and packaged as a 422.