cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
357 stars 42 forks source link

Consistent Error Code information #113

Closed rs-mobitech closed 1 year ago

rs-mobitech commented 1 year ago

Is your feature request related to a problem? Please describe. I was trying to show errors to my users. But I notice that some errors have an ErrorCode and others do not. If you reference to section of your document you will see:

["Error", ["ErrorCode","'unexpected-command'","'\oops'"], ["Latex","'\oops'"] ["Add", 1, ["Divide", 2, ["Error","'missing'"]]] ["Add", 1, ["Delimiter", ["Equal", 2, 2]]] ["Add", ["Subscript", "x", ["Error","'syntax-error'", ["Latex","'_'"]]], 1] ["Sequence", "x", ["Error", ["ErrorCode", "'unexpected-token'", "'@'"], ["Latex", "'@2'"]]]

So sometimes, there is an ErrorCode, and other times there an Error and in the one case above there is no mention of an Error in the message

Describe the solution you'd like An ErrorCode and simple for every time there is an error, that is easy to reference and provide to the user.

Describe alternatives you've considered I believe I will need to try to add some logic to extract the error information from the output of expr.errors, but it will not be simple as there are different messages formats.

Additional context None

arnog commented 1 year ago

The argument of the ["Error"] function can be either a string or an ["ErrorCode"] expression.