Opened 8 years ago

Last modified 8 years ago

#15902 new defect

catch maxima RuntimeErrors and rethrow usefully

Reported by: rws Owned by:
Priority: major Milestone: sage-6.4
Component: interfaces Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


In calculus/ symbolic_expression_from_maxima_string() should catch maxima RuntimeErrors from ecl.c and rethrow them with meaningful information, like the statement triggering the error and, if possible, the exact maxima error msg.

At the moment you only get RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

(don't know if the latter is possible)

Change History (3)

comment:1 Changed 8 years ago 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 could 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. Only the ones that don't give the incomprehensible error messages. 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.
Last edited 8 years ago by nbruin (previous) (diff)

comment:2 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:3 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.