nicolewhite / algebra.js

Build, display, and solve algebraic equations.
http://algebra.js.org
MIT License
1.34k stars 111 forks source link

fix expressions for expression #85

Open Announcement opened 6 years ago

Announcement commented 6 years ago

when setting an erroneous code, throwing a freshly created (type)error message does not display well. consider the following line of code:

new algebra.Expression(new Fraction(1,1))

old output

pay special attention to the second line of the codeblock.

$ node source/cas
C:\Users\Francis\Documents\Projects\app\node_modules\algebra.js\src\expressions.js:23
        throw new TypeError("Invalid Argument (" + variable.toString() + "): Argument must be of type String, Integer, Fraction or Term.");
        ^

TypeError: Invalid Argument (0): Argument must be of type String, Integer, Fraction or Term.
    at new Expression (C:\Users\Francis\Documents\Projects\app\node_modules\algebra.js\src\expressions.js:23:15)
    at mean (C:\Users\Francis\Documents\Projects\app\source\cas.js:72:16)
    at Object.<anonymous> (C:\Users\Francis\Documents\Projects\app\source\cas.js:86:13)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Function.Module.runMain (module.js:682:10)
    at startup (bootstrap_node.js:191:16)

New output

the same line is much cleaner and closer to what a user would expect; the actually ExpressionError: line is still the same.

C:\Users\Francis\Documents\GitHub\algebra.js\src\expressions.js:33                                
        throw new ExpressionError(variable);                                                      
        ^                                                                                         

ExpressionError: Invalid Argument (7): Argument must be of type String, Integer, Fraction or Term.
    at new ExpressionError (C:\Users\Francis\Documents\GitHub\algebra.js\src\expressions.js:7:11) 
    at new Expression (C:\Users\Francis\Documents\GitHub\algebra.js\src\expressions.js:33:15)     
    at mean (C:\Users\Francis\Documents\Projects\app\source\cas.js:78:16)                         
    at Object.<anonymous> (C:\Users\Francis\Documents\Projects\app\source\cas.js:86:13)           
    at Module._compile (module.js:641:30)                                                         
    at Object.Module._extensions..js (module.js:652:10)                                           
    at Module.load (module.js:560:32)                                                             
    at tryModuleLoad (module.js:503:12)                                                           
    at Function.Module._load (module.js:495:3)                                                    
    at Function.Module.runMain (module.js:682:10)                                                 
coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.01%) to 98.09% when pulling 932a052b7f7a005d9f696da27cb4810fea1b14d5 on Announcement:master into 8c74b87dca81a7ea74a47e08bc5a0838805124e0 on nicolewhite:master.