{"record":{"id":"038575c859f0cc9c","repo":"egametang/ET","slug":"createrobotargs-error","errorCode":null,"errorMessage":"CreateRobotArgs error!","messagePattern":"CreateRobotArgs error!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.robot/Scripts/Hotfix/Server/CreateRobotConsoleHandler.cs","lineNumber":25,"sourceCode":"    public class CreateRobotConsoleHandler: IConsoleHandler\n    {\n        public async ETTask Run(Fiber fiber, ModeContex contex, string content)\n        {\n            EntityRef<ModeContex> contexRef = contex;\n            try\n            {\n                switch (content)\n                {\n                    case ConsoleMode.CreateRobot:\n                    {\n                        Log.Console(\"CreateRobot args error!\");\n                        break;\n                    }\n                    default:\n                    {\n                        CreateRobotArgs options = null;\n                        Parser.Default.ParseArguments<CreateRobotArgs>(content.Split(' '))\n                                .WithNotParsed(error => throw new Exception($\"CreateRobotArgs error!\"))\n                                .WithParsed(o => { options = o; });\n\n                        RobotManagerComponent robotManagerComponent = fiber.Root.GetComponent<RobotManagerComponent>();\n\n                        EntityRef<RobotManagerComponent> robotManagerComponentRef = robotManagerComponent;\n                    \n                        // 创建机器人\n                        for (int i = 0; i < options.Num; ++i)\n                        {\n                            robotManagerComponent = robotManagerComponentRef;\n                            await robotManagerComponent.NewRobot(options.SchedulerType, $\"Robot_{i}\");\n                            Log.Console($\"Create Robot_{i}\");\n                        }\n                        break;\n                    }\n                }\n            }\n            finally","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.robot/Scripts/Hotfix/Server/CreateRobotConsoleHandler.cs#L7-L43","documentation":"CreateRobotConsoleHandler parses console input via CommandLineParser (Parser.Default.ParseArguments<CreateRobotArgs>). WithNotParsed throws a generic 'CreateRobotArgs error!' for any parse failure, discarding the actual errors. The case ConsoleMode.CreateRobot with no args is handled separately (just logs).","triggerScenarios":"Issuing the 'CreateRobot' console command with arguments that fail to bind to CreateRobotArgs (wrong types, missing required values, unknown verbs). The generic WithNotParsed callback throws regardless of the specific parser error.","commonSituations":"Typing the CreateRobot console command with malformed arguments (e.g. bad --num value, non-integer, missing flag); version mismatch where CreateRobotArgs gained new required fields; copy-pasting a command from docs that don't match current options.","solutions":["Run 'CreateRobot' with no args first to see the help/usage (the WithNotParsed path is bypassed).","Check CreateRobotArgs field definitions to learn the exact flags and types expected.","Pass arguments in the documented format (e.g. 'CreateRobot --num 10 --scheduler Default').","Improve the handler: include the actual parse errors in the exception message instead of a generic string."],"exampleFix":"// before: discards parse errors\n.WithNotParsed(error => throw new Exception($\"CreateRobotArgs error!\"))\n// after: surface the real errors\n.WithNotParsed(error => throw new Exception($\"CreateRobotArgs error: {string.Join(\", \", error)}\"))","handlingStrategy":"try-catch","validationCode":"// Validate args shape before invoking the console command\nif (string.IsNullOrWhiteSpace(content) || !content.StartsWith(\"--\")) {\n    Log.Console(\"Usage: CreateRobot --num <int> [--scheduler <type>]\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try { /* parse + create */ }\ncatch (Exception e) when (e.Message.Contains(\"CreateRobotArgs error\")) {\n    Log.Console($\"Invalid CreateRobot arguments. Usage: CreateRobot --num <N>. Detail: {e.Message}\");\n}","preventionTips":["Run the console command bare first to see auto-generated help.","Keep CreateRobotArgs field names in sync with documented usage.","Include the real parser errors in the exception message to aid debugging."],"tags":["robot","console","argument-parsing","commandlineparser"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}