File tree 3 files changed +109
-1
lines changed
3 files changed +109
-1
lines changed Original file line number Diff line number Diff line change @@ -127,3 +127,5 @@ dmypy.json
127
127
128
128
# Pyre type checker
129
129
.pyre /
130
+
131
+ .vscode /
Original file line number Diff line number Diff line change 1
- # purescript-exceptions.py
1
+ # A Python FFI provider for purescript-exceptions.py
2
+ Providing FFI files for https://github.com/purescript/purescript-exceptions
3
+
4
+ Available mirrors:
5
+
6
+ https://github.com/purescript-python/purescript-python-ffi-index
Original file line number Diff line number Diff line change
1
+ import traceback
2
+
3
+
4
+ def showErrorImpl (err ):
5
+ # TODO: make sure implemeted as JS
6
+ result = traceback .extract_stack (err )
7
+ if result is None :
8
+ return str (err )
9
+ else :
10
+ return result
11
+
12
+
13
+ def error (msg ):
14
+ return Exception (msg )
15
+
16
+
17
+ def message (e ):
18
+ # TODO: fix implmentation
19
+ return str (e )
20
+
21
+
22
+ # exports.message = function (e) {
23
+ # return e.message;
24
+ # };
25
+
26
+
27
+ def name (e ):
28
+ return str (type (e ))
29
+
30
+
31
+ # exports.name = function (e) {
32
+ # return e.name || "Error";
33
+ # };
34
+
35
+
36
+ def stackImpl (just ):
37
+ def _nothing (nothing ):
38
+ def ap (e ):
39
+ result = traceback .extract_stack (e )
40
+ if result is None :
41
+ return nothing
42
+ else :
43
+ return just (result )
44
+
45
+ return ap
46
+
47
+ return _nothing
48
+
49
+
50
+ # exports.stackImpl = function (just) {
51
+ # return function (nothing) {
52
+ # return function (e) {
53
+ # return e.stack ? just(e.stack) : nothing;
54
+ # };
55
+ # };
56
+ # };
57
+
58
+
59
+ def throwException (e ):
60
+ def ap ():
61
+ raise e
62
+
63
+ return ap
64
+
65
+
66
+ # exports.throwException = function (e) {
67
+ # return function () {
68
+ # throw e;
69
+ # };
70
+ # };
71
+
72
+
73
+ def catchExeception (c ):
74
+ def task (t ):
75
+ def ap ():
76
+ try :
77
+ return t ()
78
+ # TODO: is this equvilant?
79
+ except Exception as e :
80
+ return c (e )
81
+
82
+ return ap
83
+
84
+ return task
85
+
86
+
87
+ # exports.catchException = function (c) {
88
+ # return function (t) {
89
+ # return function () {
90
+ # try {
91
+ # return t();
92
+ # } catch (e) {
93
+ # if (e instanceof Error || Object.prototype.toString.call(e) === "[object Error]") {
94
+ # return c(e)();
95
+ # } else {
96
+ # return c(new Error(e.toString()))();
97
+ # }
98
+ # }
99
+ # };
100
+ # };
101
+ # };
You can’t perform that action at this time.
0 commit comments