ANS(Matrix([[1,2]])->cmp( showDimensionHints => 0, checker=>sub { ($correct,$student,$ans) = @_; my $isSquare = $student->isSquare; $ans->{ans_message} = "Your matrix has a determinant" if $isSquare && !$ans->{isPreview}; return !$isSquare; } ));
Here is a version that sets the error message that you requested.