Add stack trace to pcall'd remoteevent errors

Sending invalid data from server to client causes errors, like the example below

-- Script
local t = {
	test = false;	
}

t[3] = true

local s,e,b = pcall(function()
	game.ReplicatedStorage.RemoteEvent:FireAllClients(t) -- setup a remote event
end)
print(e)

-- Output will be "Cannot convert mixed or non-array tables: keys must be strings"

This makes it difficult to debug events that are in pcall, and i am requesting that the error have a location and line where it was called. I can’t count how many cases i’ve dealt with where i’ve had to add tons of prints to find the location of the RemoteEvent that errored because of a mixed table.

I have many remote events in my game, and I do pcall on almost all of them, mostly because of context of where I use the event (like purchases, etc) If the output is only Cannot convert mixed or non-array tables: keys must be strings in the console, I can’t find exactly area it failed.

1 Like

pcall is designed to only return the error message, not the stack trace. Is there a particular reason you are wrapping a RemoteEvent::FireAllClients in a pcall to start? All cases of errors being thrown from this should be related to object serialization, not network indeterminacy like DataStores.

Optionally, if you are only doing non-yielding calls (like FireAllClients), you can use xpcall.

local s,e,b = xpcall(function()
	game.ReplicatedStorage.RemoteEvent:FireAllClients(t) -- setup a remote event
end,function(e)
	print(e)
	--Something with debug.traceback()
end)

This seems to print the line number and script name when I tested it. I think he may be referring to the RemoteEvent case not providing either of these in the print.

local _, e = pcall(function()
    local my_var = 1 + nil
end)

print(e)
1 Like

It looks like this behavior only exists for Lua errors. When doing it with a non-Lua error (HttpService disabled, DataStore error, malformed JSON, etc), the script and line number aren’t included. This could be a bug rather than a missing feature for 1 case.

local _, e = pcall(function()
   game:GetService("HttpService"):GetAsync("http://www.google.com")
end)

print(e) -- "Http requests are not enabled. Enable via game settings"
2 Likes

That’s mostly just a demo to show the issue. My use case is much more complicated, in my space game I have a function called players.respawn (not game.Players, a module). This handles everything related to spawning a space ship for the player. The function has a pcall to handle errors that can pop up with uncertain results, the problem though is that I have many different remote events for various purposes inside that function, and moving them outside would just make it more difficult. I honestly didn’t know the difference between pcall and xpcall, but I’m definitely going to change to using it, however I am told xpcall comes with similar delay issues to spawn(), I can’t confirm that, but @Raspy_Pi told me this.

Edit: He tested it, and it’s no longer an issue apparently.

Either way, i think pcall and xpcall errors should contain stack trace

1 Like

xpcall can’t be used for functions that yield. There is another feature request for this problem.

3 Likes