Sage: Ticket #15902: catch maxima RuntimeErrors and rethrow usefully
https://trac.sagemath.org/ticket/15902
<p>
In <code>calculus/calculus.py</code>: <code>symbolic_expression_from_maxima_string()</code> should catch maxima <code>RuntimeError</code>s from <code>ecl.c</code> and rethrow them with meaningful information, like the statement triggering the error and, if possible, the exact maxima error msg.
</p>
<p>
At the moment you only get <code>RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.</code>
</p>
<p>
(don't know if the latter is possible)
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/15902
Trac 1.1.6nbruinFri, 07 Mar 2014 01:13:37 GMT
https://trac.sagemath.org/ticket/15902#comment:1
https://trac.sagemath.org/ticket/15902#comment:1
<p>
There may be several ways of approaching this problem. The main reason why this runtime error occurs is illustrated by:
</p>
<pre class="wiki">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'>
</pre><p>
The problem is that <code>maxima_eval</code> 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 <code>"#$...$"</code> construct is a reader "macro": it calls the maxima parser on the string. Problem is, this happens <em>before</em> <code>maxima_eval</code> takes control (which does set up the appropriate error catching infrastructure for maxima code).
</p>
<p>
We could run the reader under the same error catching:
</p>
<pre class="wiki">sage: maxima_eval('(read-from-string "#$1+$")')
RuntimeError: ECL says: Maxima condition. result:T$error:No error.
</pre><p>
As you can see, now the error does get processed in a different way. No useful error message comes out of it, though.
</p>
<p>
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 <code>sr_to_max</code> and <code>max_to_sr</code> and how they are used in <code>sr_integral</code>, <code>sr_limit</code> and <code>sr_sum</code>. 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.
</p>
<p>
In my opinion, <code>symbolic_expression_from_maxima_string</code> should only receive strings that parse in maxima. Only the ones that don't give the incomprehensible error messages. Actual runtime errors are caught in a meaningful way:
</p>
<pre class="wiki">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.
</pre>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/15902#comment:2
https://trac.sagemath.org/ticket/15902#comment:2
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/15902#comment:3
https://trac.sagemath.org/ticket/15902#comment:3
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
Ticket