{"record":{"id":"479bef1f4cee61de","repo":"egametang/ET","slug":"error-479bef","errorCode":null,"errorMessage":"命令行格式错误! {error}","messagePattern":"命令行格式错误! (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.loader/CodeMode/Loader/Server/Init.cs","lineNumber":19,"sourceCode":"﻿using System;\nusing CommandLine;\n\nnamespace ET\n{\n    public class Init\n    {\n        public void Start()\n        {\n            try\n            {\n                AppDomain.CurrentDomain.UnhandledException += (sender, e) =>\n                {\n                    Log.Error(e.ExceptionObject.ToString());\n                };\n\n                // 命令行参数\n                Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())\n                        .WithNotParsed(error => throw new Exception($\"命令行格式错误! {error}\"))\n                        .WithParsed((o) => World.Instance.AddSingleton(o));\n\n                // 测试用例使用单线程模式，方便重置测试环境\n                if (Options.Instance.SceneName == \"Test\")\n                {\n                    Options.Instance.SingleThread = 1;\n                    Options.Instance.Console = 1;\n                }\n                \n                World.Instance.AddSingleton<Logger>().Log = new NLogger(Options.Instance.SceneName);\n\t\t\t\t\n                ETTask.ExceptionHandler += Log.Error;\n                \n                World.Instance.AddSingleton<TimeInfo>();\n                World.Instance.AddSingleton<FiberManager>();\n                World.Instance.AddSingleton<CodeLoader>().Start();\n            }\n            catch (Exception e)","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.loader/CodeMode/Loader/Server/Init.cs#L1-L37","documentation":"Thrown inside the DotNet loader entry point (CodeMode/Loader/Server/Init.cs) when CommandLineParser fails to parse System.Environment.GetCommandLineArgs() into the Options class. The whole Start() is wrapped in try/catch that only Console.WriteLine's the exception, so a parse failure prints to console and the bootstrap silently halts (no World/CodeLoader startup).","triggerScenarios":"Passing a command-line argument that CommandLineParser cannot bind to an Options property (unknown flag, wrong type for a numeric/enum option, missing a required value). WithNotParsed invokes the lambda which throws, caught by the outer try/catch.","commonSituations":"A typo'd -- flag; a numeric option given a non-numeric value; a new required option added to Options but the launch script/startup command not updated; running the server binary with args formatted for a different version of Options.","solutions":["Inspect the printed exception for the exact parse error and the offending token; fix the command-line / launch script accordingly.","Diff the Options class against the launch arguments whenever Options changes.","Add explicit help/version handling so WithNotParsed for --help doesn't throw."],"exampleFix":"// before\nParser.Default.ParseArguments<Options>(args)\n    .WithNotParsed(error => throw new Exception($\"命令行格式错误! {error}\"))\n    .WithParsed(o => World.Instance.AddSingleton(o));\n\n// after — separate help/version from real errors\nParser.Default.ParseArguments<Options>(args)\n    .WithNotParsed(errors =>\n    {\n        if (!errors.IsHelp() && !errors.IsVersion())\n            throw new Exception($\"命令行格式错误! {errors}\");\n    })\n    .WithParsed(o => World.Instance.AddSingleton(o));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// The bootstrap already wraps Start() in try/catch (Console.WriteLine).\n// Improve diagnostics by logging the specific parse error and offending token:\ntry { /* bootstrap */ }\ncatch (Exception e) { Log.Error($\"startup failed: {e}\"); throw; }","preventionTips":["Keep the launch script and the Options class in sync; diff on every Options change.","Distinguish --help/--version from real parse errors in WithNotParsed.","Add a startup smoke test that runs the binary with the production args."],"tags":["loader","server","commandline","bootstrap","startup"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}