Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 55b6f6d

Browse files
committed
Add traceback to an execute error
1 parent c7397fb commit 55b6f6d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

graphql/impl.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ local function gql_execute(qstate, variables, operation_name)
4141

4242
local root_value = {}
4343

44-
local ok, data = pcall(execute, state.schema, qstate.ast, root_value,
45-
variables, operation_name)
44+
local traceback
45+
local ok, data = xpcall(function()
46+
return execute(state.schema, qstate.ast, root_value, variables,
47+
operation_name)
48+
end, function(err)
49+
traceback = debug.traceback()
50+
return err
51+
end)
4652
if not ok then
47-
local err = utils.serialize_error(data)
53+
local err = utils.serialize_error(data, traceback)
4854
return {errors = {err}}
4955
end
5056
return {

graphql/utils.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,21 @@ function utils.optional_require_rex()
225225
return rex, is_pcre2
226226
end
227227

228-
function utils.serialize_error(err)
228+
function utils.serialize_error(err, traceback)
229229
if type(err) == 'string' then
230-
return {message = utils.strip_error(err)}
230+
return {
231+
message = utils.strip_error(err),
232+
traceback = traceback,
233+
}
231234
elseif type(err) == 'cdata' and
232235
tostring(ffi.typeof(err)) == 'ctype<const struct error &>' then
233-
return {message = tostring(err)}
236+
return {
237+
message = tostring(err),
238+
traceback = traceback,
239+
}
234240
elseif type(err) == 'table' and type(err.message) == 'string' then
241+
local err = table.copy(err)
242+
err.traceback = traceback
235243
return err
236244
end
237245

@@ -243,6 +251,7 @@ function utils.serialize_error(err)
243251
return {
244252
message = message,
245253
orig_error = orig_error,
254+
traceback = traceback,
246255
}
247256
end
248257

0 commit comments

Comments
 (0)