Given the following code (taken from MarketplaceService.ProcessReceipt):
local success, errorMessage = pcall(function()
purchaseHistoryStore:SetAsync(playerProductKey, true)
end)
Can success be false, while having errorMessage as nil?
Is there an example of this?
If there is no error, âsuccessâ is true and error message is nil.
If there is an error, success is false and error message is not nil.
AFAIK, no it canât.
EDIT:
The pcall function calls its first argument in protected mode , so that it catches any errors while the function is running. If there are no errors, pcall returns true , plus any values returned by the call. Otherwise, it returns false , plus the error message.
It could potentially be an empty string, but it should always return something that is a string when there is an error coming from a Roblox API member.
When I was an intern at Roblox working on the home / games / games details pages in Roact, we ran into some cases where pcall returned a nil message. I donât remember what caused it, but I remember it was fun to debug. If I remember correctly, it wasnât supposed to ever return nil. In either case, it surprised the Lua Core team that it did. Good luck!
(when error is called with no arguments in a pcall, the message is âAn error occurredâ i.e print(pcall(error)) --> false An error occurred)
This is not true on Roblox; in our Lua environment, pcallâs second return value in the error case is always a string (or nil, possibly). pcall in Roblox will always try to convert the argument to a string, and default to âAn error occurredâ if it canât coerce it to one.