Skip to content

Commit e9017f9

Browse files
committed
initial commit
1 parent 73333ec commit e9017f9

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
.vscode/

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
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

python-ffi/Effect/Exeception.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
# };

0 commit comments

Comments
 (0)