Pushed a somewhat-helping changeset for some scenarios here (and other error reporting fixes) - hasn’t been fully tested to not change/provide too much info other cases but I’d prefer providing excessive info to no info whatsoever.
Repros
Resource
fxmanifest.lua
fx_version 'cerulean'
game 'common'
server_scripts {
'test.js',
'test.lua',
}
test.js
exports('promise', () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('promise');
}, 500);
});
})
exports('cb', async (cb) => {
const rv = cb('cb');
if (rv instanceof Promise) {
await rv;
}
});
exports('cbn', (cb) => {
cb('cb');
});
test.lua
exports('cb_samert', function(cb)
cb()
end)
RegisterCommand('trip', function()
CreateThread(function()
print('a')
exports[GetCurrentResourceName()]:cb(function()
print(1)
Wait(500)
print(2)
print(undefined.value)
print(3)
end)
print('b')
end)
end)
RegisterCommand('tripn', function()
CreateThread(function()
print('a')
exports[GetCurrentResourceName()]:cbn(function()
print(1)
Wait(500)
print(2)
print(undefined.value)
print(3)
end)
print('b')
end)
end)
RegisterCommand('trip_promise', function()
CreateThread(function()
exports[GetCurrentResourceName()]:cb(function()
print(1)
exports[GetCurrentResourceName()]:promise()
print(2)
print(undefined.value)
print(3)
end)
end)
end)
RegisterCommand('trip_lua', function()
CreateThread(function()
exports[GetCurrentResourceName()]:cb_samert(function()
print(1)
Wait(500)
print(2)
print(undefined.value)
print(3)
end)
end)
end)
Example output
trip
[script:error_test_48] SCRIPT ERROR: @error_test_4871908/test.lua:9:
[script:error_test_48] An error occurred while calling export `cb` in resource `error_test_4871908`:
[script:error_test_48] citizen:/scripting/lua/scheduler.lua:747: SCRIPT ERROR: @error_test_4871908/test.lua:13: attempt to index a nil value (global 'undefined')
[script:error_test_48] > ref (@error_test_4871908/test.lua:13)
[script:error_test_48] ---
[script:error_test_48] > fn (@error_test_4871908/test.lua:9)
tripn
This is arguably the ‘worst’ case here but that’s because code is kind of wrong.
[script:error_test_48] SCRIPT ERROR in promise (unhandled rejection): Error: SCRIPT ERROR: @error_test_4871908/test.lua:30: attempt to index a nil value (global 'undefined')
[script:error_test_48] > ref (@error_test_4871908/test.lua:30)
[script:error_test_48]
[script:error_test_48]
trip_promise
[script:error_test_48] SCRIPT ERROR: @error_test_4871908/test.lua:40:
[script:error_test_48] An error occurred while calling export `cb` in resource `error_test_4871908`:
[script:error_test_48] citizen:/scripting/lua/scheduler.lua:747: SCRIPT ERROR: @error_test_4871908/test.lua:44: attempt to index a nil value (global 'undefined')
[script:error_test_48] > ref (@error_test_4871908/test.lua:44)
[script:error_test_48] > process.runNextTicks [as _tickCallback] (node:internal/process/task_queues:61)
[script:error_test_48] ---
[script:error_test_48] > fn (@error_test_4871908/test.lua:40)
[script:error_test_48] > process.runNextTicks [as _tickCallback] (node:internal/process/task_queues:61)
trip_lua
[script:error_test_48] SCRIPT ERROR: @error_test_4871908/test.lua:52:
[script:error_test_48] An error occurred while calling export `cb_samert` in resource `error_test_4871908`:
[script:error_test_48] citizen:/scripting/lua/scheduler.lua:747: SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:747: SCRIPT ERROR: @error_test_4871908/test.lua:56: attempt to index a nil value (global 'undefined')
[script:error_test_48] > ref (@error_test_4871908/test.lua:56)
[script:error_test_48]
[script:error_test_48] > ref (@error_test_4871908/test.lua:2)
[script:error_test_48] ---
[script:error_test_48] > fn (@error_test_4871908/test.lua:52)