Skip to content

Commit f1c6d77

Browse files
committed
aggregate error message handling
1 parent 54e683e commit f1c6d77

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

src/eff.lua

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@ local is_eff_obj = function(obj)
6565
return type(obj) == "table" and (obj.cls == Eff.cls or obj.cls == Resend.cls)
6666
end
6767

68+
local function get_effh(eff, effeffhs)
69+
eff = tostring(eff)
70+
71+
for i = 1, #effeffhs do
72+
if tostring(effeffhs[i][1]) == eff then
73+
return effeffhs[i][2]
74+
end
75+
end
76+
end
77+
78+
local function handle_error_message(r)
79+
if type(r) == "string" and
80+
(r:match("attempt to yield from outside a coroutine")
81+
or r:match("cannot resume dead coroutine"))
82+
then
83+
return error("continuation cannot be performed twice")
84+
else
85+
return error(r)
86+
end
87+
end
88+
6889
local handler
6990
handler = function(eff, vh, effh)
7091
local is_the_eff = function(it)
@@ -114,14 +135,7 @@ handler = function(eff, vh, effh)
114135
continue = function(co, arg)
115136
local st, r = resume(co, arg)
116137
if not st then
117-
if type(r) == "string" and
118-
(r:match("attempt to yield from outside a coroutine")
119-
or r:match("cannot resume dead coroutine"))
120-
then
121-
return error("continuation cannot be performed twice")
122-
else
123-
return error(r)
124-
end
138+
return handle_error_message(r)
125139
else
126140
return handle(r)
127141
end
@@ -131,16 +145,6 @@ handler = function(eff, vh, effh)
131145
end
132146
end
133147

134-
local function get_effh(eff, effeffhs)
135-
eff = tostring(eff)
136-
137-
for i = 1, #effeffhs do
138-
if tostring(effeffhs[i][1]) == eff then
139-
return effeffhs[i][2]
140-
end
141-
end
142-
end
143-
144148
local handlers
145149
handlers = function(vh, ...)
146150
local effeffhs = {...}
@@ -190,14 +194,7 @@ handlers = function(vh, ...)
190194
continue = function(co, arg)
191195
local st, r = resume(co, arg)
192196
if not st then
193-
if type(r) == "string" and
194-
(r:match("attempt to yield from outside a coroutine")
195-
or r:match("cannot resume dead coroutine"))
196-
then
197-
return error("continuation cannot be performed twice")
198-
else
199-
return error(r)
200-
end
197+
return handle_error_message(r)
201198
else
202199
return handle(r)
203200
end

0 commit comments

Comments
 (0)