Skip to content

Commit 433387b

Browse files
committed
rename error to throw
1 parent c81ca73 commit 433387b

File tree

8 files changed

+20
-50
lines changed

8 files changed

+20
-50
lines changed

defaultMethods.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const defaultMethods = {
114114
if (Number.isNaN(res)) throw NaN
115115
return res
116116
},
117-
error: (type) => {
117+
throw: (type) => {
118118
if (Array.isArray(type)) type = type[0]
119119
if (typeof type === 'object') throw type
120120
throw { error: type }
@@ -1005,7 +1005,7 @@ defaultMethods['!!'].compile = function (data, buildState) {
10051005
defaultMethods.none.deterministic = defaultMethods.some.deterministic
10061006

10071007
// @ts-ignore Allowing a optimizeUnary attribute that can be used for performance optimizations
1008-
defaultMethods['+'].optimizeUnary = defaultMethods['-'].optimizeUnary = defaultMethods['!'].optimizeUnary = defaultMethods['!!'].optimizeUnary = defaultMethods.cat.optimizeUnary = defaultMethods.error.optimizeUnary = true
1008+
defaultMethods['+'].optimizeUnary = defaultMethods['-'].optimizeUnary = defaultMethods['!'].optimizeUnary = defaultMethods['!!'].optimizeUnary = defaultMethods.cat.optimizeUnary = defaultMethods.throw.optimizeUnary = true
10091009

10101010
export default {
10111011
...defaultMethods,

suites/divide.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@
153153
"error": true,
154154
"data": null
155155
},
156-
{
157-
"description": "Divide by NaN",
158-
"rule": { "/": [1, { "error": "NaN" }] },
159-
"error": true,
160-
"data": null
161-
},
162156
{
163157
"description": "Divide with String produces NaN",
164158
"rule": { "/": [1, "a"] },

suites/minus.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@
115115
"data": { "x": 1, "y": 2 },
116116
"result": -1
117117
},
118-
{
119-
"description": "Subtraction with NaN",
120-
"rule": { "-": [{ "error": "NaN" }, 1] },
121-
"error": true,
122-
"data": null
123-
},
124118
{
125119
"description": "Subtraction with string produces NaN",
126120
"rule": { "-": ["Hey", 1] },

suites/modulo.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@
158158
"data": { "x": 11, "y": 6 },
159159
"result": 5
160160
},
161-
{
162-
"description": "Modulo with NaN",
163-
"rule": { "%": [{ "error": "NaN" }, 1] },
164-
"error": true,
165-
"data": null
166-
},
167161
{
168162
"description": "Modulo with string produces NaN",
169163
"rule": { "%": ["Hey", 1] },

suites/multiply.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@
145145
"data": { "x": 8, "y": 2 },
146146
"result": 16
147147
},
148-
{
149-
"description": "Multiply with NaN",
150-
"rule": { "*": [{ "error": "NaN" }, 1] },
151-
"error": true,
152-
"data": null
153-
},
154148
{
155149
"description": "Multiply with string produces NaN",
156150
"rule": { "*": ["Hey", 1] },

suites/plus.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@
141141
"result": 3,
142142
"data": { "x": 1, "y": 2 }
143143
},
144-
{
145-
"description": "Addition with NaN",
146-
"rule": { "+": [{ "error": "NaN" }, 1] },
147-
"error": true,
148-
"data": null
149-
},
150144
{
151145
"description": "Addition with string produces NaN",
152146
"rule": { "+": ["Hey", 1] },

suites/error.json renamed to suites/throw.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[
22
{
33
"description": "Creates an error object",
4-
"rule": { "error": "hello" },
4+
"rule": { "throw": "hello" },
55
"data": null,
66
"error": true
77
},
88
{
99
"description": "NaN creates an error object or measured equivalent (equivalence class test)",
10-
"rule": { "error": "NaN" },
10+
"rule": { "throw": "NaN" },
1111
"data": null,
1212
"error": true
1313
},
1414
{
1515
"description": "Can throw an error object",
16-
"rule": { "error": { "val": "x" } },
16+
"rule": { "throw": { "val": "x" } },
1717
"data": { "x": { "error": "Some error" }},
1818
"error": true
1919
}

suites/try.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"# Collection of Tests for Try",
33
{
44
"description": "Coalesce an error",
5-
"rule": { "try": [{ "error": "Some error" }, 1] },
5+
"rule": { "try": [{ "throw": "Some error" }, 1] },
66
"result": 1,
77
"data": null
88
},
@@ -14,19 +14,19 @@
1414
},
1515
{
1616
"description": "Try is variadic",
17-
"rule": { "try": [{ "error": "Some error" }, { "/": [0, 0] }, 2] },
17+
"rule": { "try": [{ "throw": "Some error" }, { "/": [0, 0] }, 2] },
1818
"result": 2,
1919
"data": null
2020
},
2121
{
2222
"description": "Panics if none of the values are valid",
23-
"rule": { "try": [{ "error": "Some error" }, { "error": "Some other error" }] },
23+
"rule": { "try": [{ "throw": "Some error" }, { "throw": "Some other error" }] },
2424
"error": true,
2525
"data": null
2626
},
2727
{
2828
"description": "Panics if none of the values are valid (2)",
29-
"rule": { "try": [{ "error": "Some error" }, { "/": [0, 0] }] },
29+
"rule": { "try": [{ "throw": "Some error" }, { "/": [0, 0] }] },
3030
"error": true,
3131
"data": null
3232
},
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"description": "Panics when the only argument is an error",
41-
"rule": { "try": { "error": "Some error" } },
41+
"rule": { "try": { "throw": "Some error" } },
4242
"error": true,
4343
"data": null
4444
},
@@ -56,7 +56,7 @@
5656
},
5757
{
5858
"description": "Panic based on an error emitted from an if",
59-
"rule": { "try": [{ "if": [{"val": ["user", "admin"]}, true, { "error": "Not an admin" }] }] },
59+
"rule": { "try": [{ "if": [{"val": ["user", "admin"]}, true, { "throw": "Not an admin" }] }] },
6060
"data": { "user": { "admin": false } },
6161
"error": true
6262
},
@@ -78,7 +78,7 @@
7878
"description": "The context switches for the try coalescing to the previous error",
7979
"rule": {
8080
"try": [
81-
{ "error": "Some error" },
81+
{ "throw": "Some error" },
8282
{ "val": "error" }
8383
]
8484
},
@@ -89,7 +89,7 @@
8989
"description": "The context switches for the try coalescing to the previous error (2)",
9090
"rule": {
9191
"try": [
92-
{ "if": [true, { "error": "Some error" }, null] },
92+
{ "if": [true, { "throw": "Some error" }, null] },
9393
{ "val": "error" }
9494
]
9595
},
@@ -100,8 +100,8 @@
100100
"description": "The context switches for the try coalescing to the previous error (3)",
101101
"rule": {
102102
"try": [
103-
{ "error": "A" },
104-
{ "error": "B" },
103+
{ "throw": "A" },
104+
{ "throw": "B" },
105105
{ "val": "error" }
106106
]
107107
},
@@ -111,7 +111,7 @@
111111
{
112112
"description": "Error can pull from an error object",
113113
"rule": {
114-
"try": [{ "error": { "val": "x" } }, { "val": "error" }]
114+
"try": [{ "throw": { "val": "x" } }, { "val": "error" }]
115115
},
116116
"data": { "x": { "error": "Some error" }},
117117
"result": "Some error"
@@ -134,9 +134,9 @@
134134
"description": "Handles NaN Explicitly",
135135
"rule": {
136136
"try": [
137-
{ "if": [{ "/": [1, { "val": "x" }] }, { "error": "Some error" }, null] },
137+
{ "if": [{ "/": [1, { "val": "x" }] }, { "throw": "Some error" }, null] },
138138
{
139-
"if": [{ "===": [{ "val": "error" }, "NaN"]}, "Handled", { "error": { "val": [] } }]
139+
"if": [{ "===": [{ "val": "error" }, "NaN"]}, "Handled", { "throw": { "val": [] } }]
140140
}
141141
]
142142
},
@@ -147,8 +147,8 @@
147147
"description": "Did not NaN, so it errored",
148148
"rule": {
149149
"try": [
150-
{ "if": [{ "/": [1, { "val": "x" }] }, { "error": "Some error" }, null] },
151-
{ "if": [{ "===": [{ "val": "error" }, "NaN"]}, "Handled", { "error": { "val": [] } }] }
150+
{ "if": [{ "/": [1, { "val": "x" }] }, { "throw": "Some error" }, null] },
151+
{ "if": [{ "===": [{ "val": "error" }, "NaN"]}, "Handled", { "throw": { "val": [] } }] }
152152
]
153153
},
154154
"error": true,

0 commit comments

Comments
 (0)