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
|
import types/opt
type
JSError* = ref object of RootObj
e*: JSErrorEnum
message*: string
JSErrorEnum* = enum
# QuickJS internal errors
jeEvalError = "EvalError"
jeRangeError = "RangeError"
jeReferenceError = "ReferenceError"
jeSyntaxError = "SyntaxError"
jeTypeError = "TypeError"
jeURIError = "URIError"
jeInternalError = "InternalError"
jeAggregateError = "AggregateError"
# Chawan errors
jeDOMException = "DOMException"
JSResult*[T] = Result[T, JSError]
const QuickJSErrors* = [
jeEvalError,
jeRangeError,
jeReferenceError,
jeSyntaxError,
jeTypeError,
jeURIError,
jeInternalError,
jeAggregateError
]
proc newEvalError*(message: string): JSError =
return JSError(e: jeEvalError, message: message)
proc newRangeError*(message: string): JSError =
return JSError(e: jeRangeError, message: message)
proc newReferenceError*(message: string): JSError =
return JSError(e: jeReferenceError, message: message)
proc newSyntaxError*(message: string): JSError =
return JSError(e: jeSyntaxError, message: message)
proc newTypeError*(message: string): JSError =
return JSError(e: jeTypeError, message: message)
proc newURIError*(message: string): JSError =
return JSError(e: jeURIError, message: message)
proc newInternalError*(message: string): JSError =
return JSError(e: jeInternalError, message: message)
proc newAggregateError*(message: string): JSError =
return JSError(e: jeAggregateError, message: message)
template errTypeError*(message: string): untyped =
err(newTypeError(message))
|