[New Solver] Type Error with pcall Return Values in Luau Type Checker Beta (errorMessage Not Recognized)
When using the Luau type checker beta feature with --!strict mode, a type error occurs in my module MCS_Remotes.luau where the second return value (errorMessage) from pcall is not recognized, despite pcall always returning two values (boolean, any). This prevents proper error handling in the init function of the Modular Command System (MCS) middleware.
Error Message:
Type Error: (246,26) Function only returns 1 value, but 2 are required here
Code Context:
The error occurs in the init function at the pcall invocation:
-- MCS_Remotes.luau, line 237-303
-- Initialize the remotes system
local function init(): boolean
if isInitialized then
Utils.print(MODULE_NAME, "Remotes system already initialized")
return true
end
Utils.startTimer(MODULE_NAME, "Init")
local success, errorMessage: any = pcall(function(): ()
-- Create or get MCS folder
local mcsFolder = ReplicatedStorage:FindFirstChild("MCS")
if not mcsFolder then
mcsFolder = Instance.new("Folder")
mcsFolder.Name = "MCS"
mcsFolder.Parent = ReplicatedStorage
end
assert(mcsFolder:IsA("Folder"), "MCS folder is not a Folder instance")
-- Create or get Remotes folder
remoteFolder = mcsFolder:FindFirstChild("Remotes")
if not remoteFolder then
remoteFolder = Instance.new("Folder")
remoteFolder.Name = "Remotes"
remoteFolder.Parent = mcsFolder
end
assert(remoteFolder:IsA("Folder"), "Remotes folder is not a Folder instance")
-- Create command remote
commandRemote = Instance.new("RemoteEvent")
commandRemote.Name = "CommandRemote"
commandRemote.Parent = remoteFolder
-- Create autocomplete remote
autocompleteRemote = Instance.new("RemoteFunction")
autocompleteRemote.Name = "AutocompleteRemote"
autocompleteRemote.Parent = remoteFolder
-- Connect command remote
commandRemote.OnServerEvent:Connect(function(player: Player, request: Types.CommandRequest)
local response = handleCommandRequest(player, request)
if commandRemote then
commandRemote:FireClient(player, response)
else
Utils.print(MODULE_NAME, "Warning: commandRemote is nil during FireClient")
end
end)
-- Connect autocomplete remote
autocompleteRemote.OnServerInvoke = function(player: Player, input: string): Types.QueryResponse
return handleAutocompleteRequest(player, input)
end
isInitialized = true
Utils.print(MODULE_NAME, "Remotes system initialized successfully")
end)
Utils.endTimer(MODULE_NAME, "Init")
if not success then
Utils.print(MODULE_NAME, string.format("Failed to initialize remotes: %s", tostring(errorMessage or "Unknown error")))
return false
end
return true
end
Expected Behavior:
pcallshould return two values: aboolean(success) and anany(errorMessage).- The type checker should allow destructuring both values without error.
- The
errorMessageshould be usable in subsequent error handling (tostring(errorMessage or "Unknown error")).
Actual Behavior:
- The Luau type checker beta incorrectly infers that
pcallreturns only one value, causing a type error when assigning tosuccessanderrorMessage. - This blocks compilation and prevents proper error handling.
How to Reproduce:
- Create a Roblox Luau script (
any_name.luau) with the abovepcallcode in--!strictmode. - Enable the Luau type checker beta feature in Roblox Studio.
- Open the module.
- Observe the error at the
pcallline:Type Error: (246,26) Function only returns 1 value, but 2 are required here.
Environment:
- Luau Version: 0.678
- Roblox Studio Version: Latest stable release (Jun 17, 2025)
- Trype Checking:
--!strict - OS: MacOS
- Project Context: Modular Command System (MCS) centralized remotes that creates and handles all events within MCS on roblox, using
ReplicatedStorage.MCS.Remotesfor client-server communication
Attempted Fixes:
- Explicitly typed
success: boolean, errorMessage: any(no effect). - Explicitly typed
success: boolean, errorMessage: string(no effect). - Removed
successtype annotation, keepingerrorMessage: any(no effect). - Removed
errorMessagetype annotation, keepingsuccess: any(no effect). - Added function return type
: ()to clarify thepcallfunction’s signature (no effect). - Tried to fix this with AI (no effect).
Notes:
- The error does not occur without
--!strictAND/or beta luau type checker. - The
pcallis used to handle potential errors during folder and remote creation (Instance.new,assert, etc.). - Related modules (
MCS_Configuration,MCS_Types,MCS_Utils) do not appear to affect this issue, but I can provide them if needed. - This may be a bug in the Luau type checker beta’s handling of
pcallreturn types in strict mode. - This is not the first time I see this type warning.
Bug still not fixed.
I'm also encountering this error, here's a more concise repro. Interestingly, there's no type error if the solver can infer in compile time that the function does in fact either error or return a value.
local _success, _result = pcall(function() -- TypeError: Function only returns 1 value, but 2 are required here
if true then
error("hello")
end
end)
local _success2, _result2 = pcall(function() -- ✓
error("hello")
end)
local _success3, _result3 = pcall(function() : number -- ✓
return 5
end)
still not fixed