about summary refs log tree commit diff stats
path: root/lib/monoucha0/monoucha/jserror.nim
blob: ed3fe4f870dc1161cd53d4f39e9eae457b0b81e1 (plain) (blame)
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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #
{.push raises: [].}

import optshim

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 errEvalError*(message: string): untyped =
  err(newEvalError(message))

template errRangeError*(message: string): untyped =
  err(newRangeError(message))

template errReferenceError*(message: string): untyped =
  err(newReferenceError(message))

template errSyntaxError*(message: string): untyped =
  err(newSyntaxError(message))

template errTypeError*(message: string): untyped =
  err(newTypeError(message))

template errURIError*(message: string): untyped =
  err(newURIError(message))

template errInternalError*(message: string): untyped =
  err(newInternalError(message))

template errAggregateError*(message: string): untyped =
  err(newAggregateError(message))

{.pop.} # raises
"p">: 15 * time.Second, ReadTimeout: 15 * time.Second, } log.Printf("Listening on port %v\n", confObj.port) err := server.ListenAndServe() if err != nil { log.Printf("%v\n", err) } closelog <- true }