File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 "modules" : false ,
1111 "useBuiltIns" : true
1212 }]
13+ ],
14+ "plugins" : [
15+ [" babel-plugin-transform-builtin-extend" , {
16+ "globals" : [" Error" ]
17+ }]
1318 ]
1419}
Original file line number Diff line number Diff line change 6868 },
6969 "dependencies" : {
7070 "babel-polyfill" : " ^6.26.0" ,
71+ "babel-plugin-transform-builtin-extend" : " 1.1.2" ,
7172 "bcryptjs" : " ^2.4.3" ,
7273 "bignumber.js" : " ^6.0.0" ,
7374 "bootstrap" : " ^3.3.7" ,
Original file line number Diff line number Diff line change 88import OpModules from "./config/modules/OpModules" ;
99import OperationConfig from "./config/OperationConfig.json" ;
1010import log from "loglevel" ;
11+ import OperationError from "./errors/OperationError" ;
1112
1213/**
1314 * The Recipe controls a list of Operations and the Dish they operate on.
@@ -175,18 +176,24 @@ class Recipe {
175176 dish . set ( output , op . outputType ) ;
176177 }
177178 } catch ( err ) {
178- const e = typeof err == "string" ? { message : err } : err ;
179-
180- e . progress = i ;
181- if ( e . fileName ) {
182- e . displayStr = op . name + " - " + e . name + " in " +
183- e . fileName + " on line " + e . lineNumber +
184- ".<br><br>Message: " + ( e . displayStr || e . message ) ;
179+ // print expected errors in output pane
180+ if ( err instanceof OperationError ) {
181+ dish . set ( err . message , "string" ) ;
182+ return i ;
185183 } else {
186- e . displayStr = op . name + " - " + ( e . displayStr || e . message ) ;
184+ const e = typeof err == "string" ? { message : err } : err ;
185+
186+ e . progress = i ;
187+ if ( e . fileName ) {
188+ e . displayStr = op . name + " - " + e . name + " in " +
189+ e . fileName + " on line " + e . lineNumber +
190+ ".<br><br>Message: " + ( e . displayStr || e . message ) ;
191+ } else {
192+ e . displayStr = op . name + " - " + ( e . displayStr || e . message ) ;
193+ }
194+
195+ throw e ;
187196 }
188-
189- throw e ;
190197 }
191198 }
192199
Original file line number Diff line number Diff line change 1+ /**
2+ * Create custom error type for handling operation input errors.
3+ * i.e. where the operation can handle the error and print a
4+ * message to the screen.
5+ */
6+ class OperationError extends Error {
7+ /**
8+ * Standard error constructor. Adds no new behaviour.
9+ * @param args standard error args
10+ */
11+ constructor ( ...args ) {
12+ super ( ...args ) ;
13+
14+ if ( Error . captureStackTrace ) {
15+ Error . captureStackTrace ( this , OperationError ) ;
16+ }
17+ }
18+ }
19+
20+ export default OperationError ;
Original file line number Diff line number Diff line change 55 */
66
77import Operation from "../Operation" ;
8+ import OperationError from "../errors/OperationError" ;
89
910/**
1011 * Set cartesian product operation
@@ -44,7 +45,8 @@ class CartesianProduct extends Operation {
4445 */
4546 validateSampleNumbers ( sets ) {
4647 if ( ! sets || sets . length < 2 ) {
47- throw "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?" ;
48+ throw new OperationError ( "Incorrect number of sets, perhaps you" +
49+ " need to modify the sample delimiter or add more samples?" ) ;
4850 }
4951 }
5052
@@ -54,16 +56,13 @@ class CartesianProduct extends Operation {
5456 * @param {string } input
5557 * @param {Object[] } args
5658 * @returns {string }
59+ * @throws {OperationError }
5760 */
5861 run ( input , args ) {
5962 [ this . sampleDelim , this . itemDelimiter ] = args ;
6063 const sets = input . split ( this . sampleDelim ) ;
6164
62- try {
63- this . validateSampleNumbers ( sets ) ;
64- } catch ( e ) {
65- return e ;
66- }
65+ this . validateSampleNumbers ( sets ) ;
6766
6867 return this . runCartesianProduct ( ...sets . map ( s => s . split ( this . itemDelimiter ) ) ) ;
6968 }
Original file line number Diff line number Diff line change 55 */
66
77import Operation from "../Operation" ;
8+ import OperationError from "../errors/OperationError" ;
89
910/**
1011 * Set Difference operation
@@ -44,7 +45,7 @@ class SetDifference extends Operation {
4445 */
4546 validateSampleNumbers ( sets ) {
4647 if ( ! sets || ( sets . length !== 2 ) ) {
47- throw "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?" ;
48+ throw new OperationError ( "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?" ) ;
4849 }
4950 }
5051
@@ -54,16 +55,13 @@ class SetDifference extends Operation {
5455 * @param {string } input
5556 * @param {Object[] } args
5657 * @returns {string }
58+ * @throws {OperationError }
5759 */
5860 run ( input , args ) {
5961 [ this . sampleDelim , this . itemDelimiter ] = args ;
6062 const sets = input . split ( this . sampleDelim ) ;
6163
62- try {
63- this . validateSampleNumbers ( sets ) ;
64- } catch ( e ) {
65- return e ;
66- }
64+ this . validateSampleNumbers ( sets ) ;
6765
6866 return this . runSetDifference ( ...sets . map ( s => s . split ( this . itemDelimiter ) ) ) ;
6967 }
Original file line number Diff line number Diff line change 55 */
66
77import Operation from "../Operation" ;
8+ import OperationError from "../errors/OperationError" ;
89
910/**
1011 * Set Intersection operation
@@ -44,7 +45,7 @@ class SetIntersection extends Operation {
4445 */
4546 validateSampleNumbers ( sets ) {
4647 if ( ! sets || ( sets . length !== 2 ) ) {
47- throw "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?" ;
48+ throw new OperationError ( "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?" ) ;
4849 }
4950 }
5051
@@ -54,16 +55,13 @@ class SetIntersection extends Operation {
5455 * @param {string } input
5556 * @param {Object[] } args
5657 * @returns {string }
58+ * @throws {OperationError }
5759 */
5860 run ( input , args ) {
5961 [ this . sampleDelim , this . itemDelimiter ] = args ;
6062 const sets = input . split ( this . sampleDelim ) ;
6163
62- try {
63- this . validateSampleNumbers ( sets ) ;
64- } catch ( e ) {
65- return e ;
66- }
64+ this . validateSampleNumbers ( sets ) ;
6765
6866 return this . runIntersect ( ...sets . map ( s => s . split ( this . itemDelimiter ) ) ) ;
6967 }
You can’t perform that action at this time.
0 commit comments