diff --git a/Cmdr/CmdrClient/init.lua b/Cmdr/CmdrClient/init.lua index b3cf7f7b..75fefdb7 100644 --- a/Cmdr/CmdrClient/init.lua +++ b/Cmdr/CmdrClient/init.lua @@ -7,7 +7,7 @@ local Util = require(Shared:WaitForChild("Util")) if RunService:IsClient() == false then error( - "Server scripts cannot require the client library. Please require the server library to use Cmdr in your own code." + "[Cmdr] Server scripts cannot require the client library. Please require the server library from the server to use Cmdr in your own code." ) end diff --git a/Cmdr/Shared/Argument.lua b/Cmdr/Shared/Argument.lua index 016dc4a1..82ce286d 100644 --- a/Cmdr/Shared/Argument.lua +++ b/Cmdr/Shared/Argument.lua @@ -145,7 +145,7 @@ function Argument.new(command, argumentDefinition, value) self.Prefix = prefix if self.Type == nil then - error(string.format("%s has an unregistered type %q", self.Name or "", parsedType or "")) + error((`[Cmdr] {self.Name or "none"} has an unregistered type %q`):format(parsedType or "")) end end @@ -376,7 +376,7 @@ function Argument:GetValue(): any local parsedValue = self:ParseValue(i) if type(parsedValue) ~= "table" then - error(("Listable types must return a table from Parse (%s)"):format(self.Type.Name)) + error(`[Cmdr] Listable types must return a table from Parse {self.Type.Name}`) end for _, value in pairs(parsedValue) do diff --git a/Cmdr/Shared/Command.lua b/Cmdr/Shared/Command.lua index c3f7fd12..18bb9a61 100644 --- a/Cmdr/Shared/Command.lua +++ b/Cmdr/Shared/Command.lua @@ -65,7 +65,7 @@ function Command:Parse(allowIncompleteArguments) local required = (definition.Default == nil and definition.Optional ~= true) if required and hadOptional then - error(("Command %q: Required arguments cannot occur after optional arguments."):format(self.Name)) + error(("[Cmdr] Command %q: Required arguments cannot occur after optional arguments."):format(self.Name)) elseif not required then hadOptional = true end @@ -130,7 +130,7 @@ end -- Command:Validate() must be called before this is called or it will throw. function Command:Run() if self._Validated == nil then - error("Must validate a command before running.") + error("[Cmdr] Must validate a command before running.") end local beforeRunHook = self.Dispatcher:RunHooks("BeforeRun", self) @@ -160,11 +160,10 @@ function Command:Run() elseif IsServer then -- Uh oh, we're already on the server and there's no Run function. if self.Object.ClientRun then warn( - self.Name, - "command fell back to the server because ClientRun returned nil, but there is no server implementation! Either return a string from ClientRun, or create a server implementation for this command." + `[Cmdr] {self.Name} command fell back to the server because ClientRun returned nil, but there is no server implementation! Either return a string from ClientRun, or create a server implementation for this command.` ) else - warn(self.Name, "command has no implementation!") + warn(`[Cmdr] {self.Name} command has no implementation!`) end self.Response = "No implementation." @@ -204,14 +203,16 @@ end -- Sends an event message to a player function Command:SendEvent(player, event, ...) - assert(typeof(player) == "Instance", "Argument #1 must be a Player") - assert(player:IsA("Player"), "Argument #1 must be a Player") - assert(type(event) == "string", "Argument #2 must be a string") + assert(typeof(player) == "Instance" and player:IsA("Player"), "[Cmdr] Argument #1 must be a Player") + assert(type(event) == "string", "[Cmdr] Argument #2 must be a string") if IsServer then self.Dispatcher.Cmdr.RemoteEvent:FireClient(player, event, ...) elseif self.Dispatcher.Cmdr.Events[event] then - assert(player == Players.LocalPlayer, "Event messages can only be sent to the local player on the client.") + assert( + player == Players.LocalPlayer, + "[Cmdr] Event messages can only be sent to the local player on the client." + ) self.Dispatcher.Cmdr.Events[event](...) end end @@ -219,7 +220,7 @@ end -- Sends an event message to all players function Command:BroadcastEvent(...) if not IsServer then - error("Can't broadcast event messages from the client.", 2) + error("[Cmdr] Can't broadcast event messages from the client.", 2) end self.Dispatcher.Cmdr.RemoteEvent:FireAllClients(...) diff --git a/Cmdr/Shared/Dispatcher.lua b/Cmdr/Shared/Dispatcher.lua index edceb3ca..05938b86 100644 --- a/Cmdr/Shared/Dispatcher.lua +++ b/Cmdr/Shared/Dispatcher.lua @@ -44,7 +44,7 @@ local Dispatcher = { ]=] function Dispatcher:Evaluate(text: string, executor: Player, allowIncompleteArguments: boolean?, data: any?) if RunService:IsClient() == true and executor ~= Players.LocalPlayer then - error("Can't evaluate a command that isn't sent by the local player.") + error("[Cmdr] Can't evaluate a command that isn't sent by the local player.") end local arguments = Util.SplitString(text) @@ -125,7 +125,7 @@ function Dispatcher:EvaluateAndRun( end) if not ok then - warn(("Error occurred while evaluating command string %q\n%s"):format(text, tostring(out))) + warn((`[Cmdr] Error occurred while evaluating command string %q\n{tostring(out)}`):format(text)) end return ok and out or "An error occurred while running this command. Check the console for more information." @@ -143,7 +143,7 @@ end ]=] function Dispatcher:Send(text: string, data: any?) if RunService:IsClient() == false then - error("Dispatcher:Send can only be called from the client.") + error("[Cmdr] Dispatcher:Send can only be called from the client.") end return self.Cmdr.RemoteFunction:InvokeServer(text, { @@ -163,7 +163,7 @@ end ]=] function Dispatcher:Run(...): string if not Players.LocalPlayer then - error("Dispatcher:Run can only be called from the client.") + error("[Cmdr] Dispatcher:Run can only be called from the client.") end local args = { ... } @@ -235,7 +235,7 @@ end ]=] function Dispatcher:RunHooks(hookName: string, commandContext, ...) if not self.Registry.Hooks[hookName] then - error(("Invalid hook name: %q"):format(hookName), 2) + error(("[Cmdr] Invalid hook name: %q"):format(hookName), 2) end if @@ -276,7 +276,7 @@ end Inserts the string into the window history ]=] function Dispatcher:PushHistory(text: string) - assert(RunService:IsClient(), "PushHistory may only be used from the client.") + assert(RunService:IsClient(), "[Cmdr] PushHistory may only be used from the client.") local history = self:GetHistory() @@ -297,7 +297,7 @@ end Returns an array of the user's command history. Most recent commands are inserted at the end of the array. ]=] function Dispatcher:GetHistory(): { string } - assert(RunService:IsClient(), "GetHistory may only be used from the client.") + assert(RunService:IsClient(), "[Cmdr] GetHistory may only be used from the client.") return TeleportService:GetTeleportSetting(HISTORY_SETTING_NAME) or {} end diff --git a/Cmdr/Shared/Registry.lua b/Cmdr/Shared/Registry.lua index 9117fc4e..36446d6a 100644 --- a/Cmdr/Shared/Registry.lua +++ b/Cmdr/Shared/Registry.lua @@ -158,25 +158,23 @@ local Registry = { ]=] function Registry:RegisterType(name: string, typeObject) if not name or typeof(name) ~= "string" then - error("Invalid type name provided: nil") + error("[Cmdr] Invalid type name provided: nil") end if not name:find("^[%d%l]%w*$") then error( - ('Invalid type name provided: "%s", type names must be alphanumeric and start with a lower-case letter or a digit.'):format( - name - ) + `[Cmdr] Invalid type name provided: "{name}", type names must be alphanumeric and start with a lower-case letter or a digit.` ) end for key in pairs(typeObject) do if self.TypeMethods[key] == nil then - error('Unknown key/method in type "' .. name .. '": ' .. key) + error(`[Cmdr] Unknown key/method in type "{name}": {key}`) end end if self.Types[name] ~= nil then - error(('Type "%s" has already been registered.'):format(name)) + error(`[Cmdr] Type {name} has already been registered.`) end typeObject.Name = name @@ -215,7 +213,7 @@ end @within Registry ]=] function Registry:RegisterTypeAlias(name: string, alias: string) - assert(self.TypeAliases[name] == nil, ("Type alias %s already exists!"):format(alias)) + assert(self.TypeAliases[name] == nil, `[Cmdr] Type alias {alias} already exists!`) self.TypeAliases[name] = alias end @@ -259,7 +257,7 @@ Registry.RegisterHooksIn = Registry.RegisterTypesIn function Registry:RegisterCommandObject(commandObject) for key in pairs(commandObject) do if self.CommandMethods[key] == nil then - error("Unknown key/method in command " .. (commandObject.Name or "unknown command") .. ": " .. key) + error(`[Cmdr] Unknown key/method in command "{commandObject.Name or "unknown command"}": {key}`) end end @@ -269,11 +267,7 @@ function Registry:RegisterCommandObject(commandObject) for key in pairs(arg) do if self.CommandArgProps[key] == nil then error( - ('Unknown property in command "%s" argument #%d: %s'):format( - commandObject.Name or "unknown", - i, - key - ) + `[Cmdr] Unknown property in command "{commandObject.Name or "unknown"}" argument #{i}: {key}` ) end end @@ -321,11 +315,11 @@ function Registry:RegisterCommand( local commandObject = require(commandScript) assert( typeof(commandObject) == "table", - `Invalid return value from command script "{commandScript.Name}" (CommandDefinition expected, got {typeof(commandObject)})` + `[Cmdr] Invalid return value from command script "{commandScript.Name}" (CommandDefinition expected, got {typeof(commandObject)})` ) if commandServerScript then - assert(RunService:IsServer(), "The commandServerScript parameter is not valid for client usage.") + assert(RunService:IsServer(), "[Cmdr] The commandServerScript parameter is not valid for client usage.") commandObject.Run = require(commandServerScript) end @@ -373,9 +367,7 @@ function Registry:RegisterCommandsIn(container: Instance, filter: ((any) -> bool for skippedScript in pairs(skippedServerScripts) do if not usedServerScripts[skippedScript] then warn( - "Command script " - .. skippedScript.Name - .. " was skipped because it has 'Server' in its name, and has no equivalent shared script." + `[Cmdr] Command script {skippedScript.Name} was skipped because it has 'Server' in its name, and has no equivalent shared script.` ) end end @@ -395,7 +387,7 @@ end @within Registry ]=] function Registry:RegisterDefaultCommands(arrayOrFunc: { string } | (any) -> boolean | nil) - assert(RunService:IsServer(), "RegisterDefaultCommands cannot be called from the client.") + assert(RunService:IsServer(), "[Cmdr] RegisterDefaultCommands cannot be called from the client.") local dictionary = if type(arrayOrFunc) == "table" then Util.MakeDictionary(arrayOrFunc) else nil @@ -488,7 +480,7 @@ end ]=] function Registry:RegisterHook(hookName: string, callback: (any) -> string?, priority: number) if not self.Hooks[hookName] then - error(("Invalid hook name: %q"):format(hookName), 2) + error(("[Cmdr] Invalid hook name: %q"):format(hookName), 2) end table.insert(self.Hooks[hookName], { callback = callback, priority = priority or 0 }) diff --git a/Cmdr/Shared/Util.lua b/Cmdr/Shared/Util.lua index c2d5ba2b..43fcfb4f 100644 --- a/Cmdr/Shared/Util.lua +++ b/Cmdr/Shared/Util.lua @@ -72,12 +72,12 @@ function Util.MakeFuzzyFinder(setOrContainer: any): (string, boolean?, boolean?) elseif type(setOrContainer[1]) == "string" then names = setOrContainer elseif setOrContainer[1] ~= nil then - error("MakeFuzzyFinder only accepts tables of instances or strings.") + error("[Cmdr] MakeFuzzyFinder only accepts tables of instances or strings.") else names = {} end else - error("MakeFuzzyFinder only accepts a table, Enum, or Instance.") + error("[Cmdr] MakeFuzzyFinder only accepts a table, Enum, or Instance.") end -- Searches the set (checking exact matches first) @@ -488,7 +488,7 @@ function Util.MakeSequenceType(options) assert( options.Parse ~= nil or options.Constructor ~= nil, - "MakeSequenceType: Must provide one of: Constructor, Parse" + "[Cmdr] MakeSequenceType: Must provide one of: Constructor, Parse" ) options.TransformEach = options.TransformEach or function(...) diff --git a/Cmdr/init.lua b/Cmdr/init.lua index 1f0d587e..627cc1fd 100644 --- a/Cmdr/init.lua +++ b/Cmdr/init.lua @@ -2,7 +2,9 @@ local RunService = game:GetService("RunService") local Util = require(script.Shared:WaitForChild("Util")) if RunService:IsServer() == false then - error("Cmdr server module is somehow running on a client!") + error( + "[Cmdr] Client scripts cannot require the server library. Please require the client library from the client to use Cmdr in your own code." + ) end --[=[