Repository navigation
Expand file tree
/
Copy pathStdlib_JsError.resi
More file actions
246 lines (191 loc) · 7.32 KB
/
Copy pathStdlib_JsError.resi
File metadata and controls
246 lines (191 loc) · 7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/***
Functions for working with JavaScript errors.
See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) on MDN.
*/
/** Represents a JavaScript error. */
@instanceOf("Error")
type t
/**
`stack(error)` retrieves the `stack` property of the error, if it exists. The stack is a list of what functions were called, and what files they are defined in, prior to the error happening.
See [`Error.prototype.stack`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack) on MDN.
## Example
```rescript
let error = JsError.make("error")
Console.log(error->JsError.stack) // Logs `stack` if it exists on `someError`
```
*/
@get
external stack: t => option<string> = "stack"
/**
`message(error)` retrieves the `message` property of the error.
See [`Error.prototype.message`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message) on MDN.
## Example
```rescript
let error = JsError.SyntaxError.make("Some message here")
error->JsError.message == "Some message here"
```
*/
@get
external message: t => string = "message"
/**
`name(error)` retrieves the `name` property of the error.
See [`Error.prototype.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) on MDN.
## Example
```rescript
let error = JsError.SyntaxError.make("Some message here")
error->JsError.name == "SyntaxError"
```
*/
@get
external name: t => string = "name"
/**
`fileName(error)` retrieves the `fileName` property of the error, if it exists.
See [`Error.prototype.fileName`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/fileName) on MDN.
*/
@get
external fileName: t => option<string> = "fileName"
/**
`make(message)` creates a new error, setting its `message` to the provided value.
See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error) on MDN.
## Example
```rescript
let error = JsError.make("Some message here")
error->JsError.message == "Some message here"
error->JsError.name == "Error"
```
*/
@new
external make: string => t = "Error"
module EvalError: {
/**
Creates a new `EvalError` with the provided `message`.
See [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) on MDN.
*/
@new
external make: string => t = "EvalError"
/**
Creates a new `EvalError` with the provided `message` and throws it.
`JsError.EvalError.throwWithMessage("message")` is equivalent to `JsError.EvalError.make("message")->JsError.throw`.
See [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) on MDN.
*/
let throwWithMessage: string => 'a
}
module RangeError: {
/**
Creates a new `RangeError` with the provided `message`.
See [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) on MDN.
*/
@new
external make: string => t = "RangeError"
/**
Creates a new `RangeError` with the provided `message` and throws it.
`JsError.RangeError.throwWithMessage("message")` is equivalent to `JsError.RangeError.make("message")->JsError.throw`.
See [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) on MDN.
*/
let throwWithMessage: string => 'a
}
module ReferenceError: {
/**
Creates a new `ReferenceError` with the provided `message`.
See [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) on MDN.
*/
@new
external make: string => t = "ReferenceError"
/**
Creates a new `ReferenceError` with the provided `message` and throws it.
`JsError.ReferenceError.throwWithMessage("message")` is equivalent to `JsError.ReferenceError.make("message")->JsError.throw`.
See [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) on MDN.
*/
let throwWithMessage: string => 'a
}
module SyntaxError: {
/**
Creates a new `SyntaxError` with the provided `message`.
See [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) on MDN.
*/
@new
external make: string => t = "SyntaxError"
/**
Creates a new `SyntaxError` with the provided `message` and throws it.
`JsError.SyntaxError.throwWithMessage("message")` is equivalent to `JsError.SyntaxError.make("message")->JsError.throw`.
See [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) on MDN.
*/
let throwWithMessage: string => 'a
}
module TypeError: {
/**
Creates a new `TypeError` with the provided `message`.
See [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) on MDN.
*/
@new
external make: string => t = "TypeError"
/**
Creates a new `TypeError` with the provided `message` and throws it.
`JsError.TypeError.throwWithMessage("message")` is equivalent to `JsError.TypeError.make("message")->JsError.throw`.
See [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) on MDN.
*/
let throwWithMessage: string => 'a
}
module URIError: {
/**
Creates a new `URIError` with the provided `message`.
See [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) on MDN.
*/
@new
external make: string => t = "URIError"
/**
Creates a new `URIError` with the provided `message` and throws it.
`JsError.URIError.throwWithMessage("message")` is equivalent to `JsError.URIError.make("message")->JsError.throw`.
See [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) on MDN.
*/
let throwWithMessage: string => 'a
}
/**
Throws the given error, terminating execution unless caught by a surrounding try/catch block.
## Examples
```rescript
let error = JsError.make("Everything is upside down.")
if 5 > 10 {
JsError.throw(error)
} else {
Console.log("Phew, sanity still rules.")
}
```
*/
external throw: t => 'a = "%raise"
/**
Creates a new `Error` with the provided `message` and throws it.
`JsError.throwWithMessage("message")` is equivalent to `JsError.make("message")->JsError.throw`.
*/
let throwWithMessage: string => 'a
/**
Throws a panic exception with the given message.
A panic exception is a native JavaScript exception that is not intended to be caught and
handled. Compared to a ReScript exception this will give a better stack trace and
debugging experience.
## Examples
```rescript
try {
JsError.panic("Uh oh. This was unexpected!")
} catch {
| JsExn(obj) =>
switch JsExn.message(obj) {
| Some(m) => assert(m == "Panic! Uh oh. This was unexpected!")
| None => assert(false)
}
| _ => assert(false)
}
```
*/
let panic: string => 'a
/**
Casts a `JsError.t` to a `JsExn.t`.
This is useful when you want to compare a JS exception and a JS error.
*/
external toJsExn: t => Stdlib_JsExn.t = "%identity"
/**
`ignore(error)` ignores the provided error and returns unit.
This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
without having to store or process it further.
*/
external ignore: t => unit = "%ignore"