forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStdlib_Error.resi
More file actions
277 lines (237 loc) · 7.33 KB
/
Copy pathStdlib_Error.resi
File metadata and controls
277 lines (237 loc) · 7.33 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/***
Functions for working with JavaScript exceptions.
See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) on MDN.
*/
@@deprecated("Use `JsError` module")
/** Represents a JavaScript exception. */
@deprecated({
reason: "Use `JsError.t` instead",
migrate: %replace.type(: JsError.t),
})
type t = Stdlib_Exn.t
@deprecated({
reason: "Use `JsExn.fromException` instead",
migrate: JsExn.fromException(),
})
let fromException: exn => option<t>
/**
Turns an `Error.t` into an `exn`.
## Examples
```rescript
let error = Error.make("Something went wrong.")
let asExn = error->Error.toException // `asExn` is now type `exn`
```
*/
@deprecated("Use functions from `JsExn` instead")
external toException: t => exn = "%identity"
/**
`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 = Error.make("error")
Console.log(error->Error.stack) // Logs `stack` if it exists on `someError`
```
*/
@deprecated({
reason: "Use `JsError.stack` instead",
migrate: JsError.stack(),
})
@get
external stack: t => option<string> = "stack"
/**
`message(error)` retrieves the `message` property of the error, if it exists.
See [`Error.prototype.message`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message) on MDN.
## Example
```rescript
let error = Error.SyntaxError.make("Some message here")
Console.log(error->Error.message) // Logs "Some message here" to the console
```
*/
@deprecated({
reason: "Use `JsError.message` instead",
migrate: JsError.message(),
})
@get
external message: t => option<string> = "message"
/**
`name(error)` retrieves the `name` property of the error, if it exists.
See [`Error.prototype.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) on MDN.
## Example
```rescript
let error = Error.SyntaxError.make("Some message here")
Console.log(error->Error.name) // Logs "SyntaxError" to the console
```
*/
@deprecated({
reason: "Use `JsError.name` instead",
migrate: JsError.name(),
})
@get
external name: t => option<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.
*/
@deprecated({
reason: "Use `JsError.fileName` instead",
migrate: JsError.fileName(),
})
@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 = Error.make("Some message here")
Console.log(error->Error.message) // Logs "Some message here" to the console
Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error
```
*/
@deprecated({
reason: "Use `JsError.make` instead",
migrate: JsError.make(),
})
@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.
*/
@deprecated({
reason: "Use `JsError.EvalError.make` instead",
migrate: JsError.EvalError.make(),
})
@new
external make: string => t = "EvalError"
}
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.
*/
@deprecated({
reason: "Use `JsError.RangeError.make` instead",
migrate: JsError.RangeError.make(),
})
@new
external make: string => t = "RangeError"
}
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.
*/
@deprecated({
reason: "Use `JsError.ReferenceError.make` instead",
migrate: JsError.ReferenceError.make(),
})
@new
external make: string => t = "ReferenceError"
}
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.
*/
@deprecated({
reason: "Use `JsError.SyntaxError.make` instead",
migrate: JsError.SyntaxError.make(),
})
@new
external make: string => t = "SyntaxError"
}
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.
*/
@deprecated({
reason: "Use `JsError.TypeError.make` instead",
migrate: JsError.TypeError.make(),
})
@new
external make: string => t = "TypeError"
}
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.
*/
@deprecated({
reason: "Use `JsError.URIError.make` instead",
migrate: JsError.URIError.make(),
})
@new
external make: string => t = "URIError"
}
/**
Raises (throws in JavaScript language) the provided `Error.t`, which will stop execution.
## Examples
```rescript
let error = Error.make("Everything is upside down.")
if 5 > 10 {
error->Error.raise
} else {
Console.log("Phew, sanity still rules.")
}
```
*/
@deprecated({
reason: "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `JsError.throw` instead",
migrate: JsError.throw(),
})
external raise: t => 'a = "%raise"
/**
Throws the given exception, terminating execution unless caught by a surrounding try/catch block.
## Examples
```rescript
let error = Error.make("Everything is upside down.")
if 5 > 10 {
Error.throw(error)
} else {
Console.log("Phew, sanity still rules.")
}
```
*/
@deprecated({
reason: "Use `JsError.throw` instead",
migrate: JsError.throw(),
})
external throw: t => 'a = "%raise"
/**
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 {
Error.panic("Uh oh. This was unexpected!")
} catch {
| Exn.Error(obj) =>
switch Exn.message(obj) {
| Some(m) => assert(m == "Panic! Uh oh. This was unexpected!")
| None => assert(false)
}
| _ => assert(false)
}
```
*/
@deprecated({
reason: "Use `JsError.panic` instead",
migrate: JsError.panic(),
})
let panic: string => 'a
/**
`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.
*/
@deprecated({
reason: "Use `JsError.ignore` instead",
migrate: JsError.ignore(),
})
external ignore: t => unit = "%ignore"