#15902: catch maxima RuntimeErrors and rethrow usefully
------------------------------+------------------------
       Reporter:  rws         |        Owner:
           Type:  defect      |       Status:  new
       Priority:  major       |    Milestone:  sage-6.2
      Component:  interfaces  |   Resolution:
       Keywords:              |    Merged in:
        Authors:              |    Reviewers:
Report Upstream:  N/A         |  Work issues:
         Branch:              |       Commit:
   Dependencies:              |     Stopgaps:
------------------------------+------------------------

Comment (by nbruin):

 There may be several ways of approaching this problem. The main reason why
 this runtime error occurs is illustrated by:
 {{{
 sage: from sage.interfaces.maxima_lib import maxima_eval
 sage: maxima_eval("#$1+$")
 RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.
 sage: type(maxima_eval)
 <type 'sage.libs.ecl.EclObject'>
 }}}
 The problem is that `maxima_eval` itself is a wrapper around a lisp
 function. When called with a string argument, the default is to convert
 that string to a lisp expression via the lisp "reader" (think parser). The
 `"#$...$"` construct is a reader "macro": it calls the maxima parser on
 the string. Problem is, this happens ''before'' `maxima_eval` takes
 control (which does set up the appropriate error catching infrastructure
 for maxima code).

 We should run the reader under the same error catching:
 {{{
 sage: maxima_eval('(read-from-string "#$1+$")')
 RuntimeError: ECL says: Maxima condition. result:T$error:No error.
 }}}
 As you can see, now the error does get processed in a different way. No
 useful error message comes out of it, though.

 When I wrote this, it was really with the idea that it would be an error
 of the calculus library if maxima were fed a syntax error. Nearly all the
 translation between sage and maxima can be done on a deeper level than
 string back-and-forth parsing. See `sr_to_max` and `max_to_sr` and how
 they are used in `sr_integral`, `sr_limit` and `sr_sum`. It was originally
 the idea that the calculus-to-maxima_lib interface would eventually almost
 do away completely with string passing. As it turned out, this hasn't been
 such a priority.

 In my opinion, `symbolic_expression_from_maxima_string` should only
 receive strings that parse in maxima. Those are the ones that give the
 incomprehensible error message. Actual runtime errors are caught in a
 meaningful way:
 {{{
 sage: sage.calculus.calculus.symbolic_expression_from_maxima_string("1/0")
 RuntimeError: ECL says: Error executing code in Maxima: expt: undefined: 0
 to a negative exponent.
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/15902#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to