{"record":{"id":"9ad05bc225f0df84","repo":"microsoft/garnet","slug":"encountered-an-error-when-initializing-garnet-serv","errorCode":null,"errorMessage":"Encountered an error when initializing Garnet server. Please see log messages above for more details.","messagePattern":"Encountered an error when initializing Garnet server\\. Please see log messages above for more details\\.","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"critical","filePath":"libs/host/GarnetServer.cs","lineNumber":99,"sourceCode":"        public GarnetServer(string[] commandLineArgs, ILoggerFactory loggerFactory = null, bool cleanupDir = false, IAuthenticationSettings authenticationSettingsOverride = null)\n        {\n            Trace.Listeners.Add(new ConsoleTraceListener());\n\n            // Set up an initial memory logger to log messages from configuration parser into memory.\n            using (var memLogProvider = new MemoryLoggerProvider())\n            {\n                this.initLogger = (MemoryLogger)memLogProvider.CreateLogger(\"ArgParser\");\n            }\n\n            if (!ServerSettingsManager.TryParseCommandLineArguments(commandLineArgs, out var serverSettings, out _, out _, out var exitGracefully, logger: this.initLogger))\n            {\n                if (exitGracefully)\n                    Environment.Exit(0);\n\n                // Flush logs from memory logger\n                FlushMemoryLogger(this.initLogger, \"ArgParser\", loggerFactory);\n\n                throw new GarnetException(\"Encountered an error when initializing Garnet server. Please see log messages above for more details.\");\n            }\n\n            if (loggerFactory == null)\n            {\n                // If the main logger factory is created by GarnetServer, it should be disposed when GarnetServer is disposed\n                disposeLoggerFactory = true;\n            }\n            else\n            {\n                this.initLogger.LogWarning(\n                    $\"Received an external ILoggerFactory object. The following configuration options are ignored: {nameof(serverSettings.FileLogger)}, {nameof(serverSettings.LogLevel)}, {nameof(serverSettings.DisableConsoleLogger)}.\");\n            }\n\n            // If no logger factory is given, set up main logger factory based on parsed configuration values,\n            // otherwise use given logger factory.\n            this.loggerFactory = loggerFactory ?? LoggerFactory.Create(builder =>\n            {\n                if (!serverSettings.DisableConsoleLogger.GetValueOrDefault())","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/host/GarnetServer.cs#L81-L117","documentation":"Thrown by the GarnetServer constructor when ServerSettingsManager.TryParseCommandLineArguments returns false and exitGracefully is false. This means the command-line arguments could not be parsed and the error is not a graceful exit condition (like --help). The actual parse errors are logged to the memory logger before this exception is thrown; the message directs you to those preceding logs.","triggerScenarios":"Starting GarnetServer with invalid or malformed command-line arguments that fail parsing (not --help/--version which set exitGracefully=true). Common causes: unknown flags, missing required values, type mismatches in argument values.","commonSituations":"Deploying with a typo in command-line flags; upgrading Garnet and using removed/renamed CLI arguments; scripting errors in container orchestration that pass wrong arguments; missing values for options that require them.","solutions":["Read the log output immediately preceding the exception — it contains the specific parse error from the ArgParser memory logger.","Run the server with --help to see the list of valid command-line arguments for your version.","Fix the malformed or unknown argument in your startup command or container entrypoint.","Validate arguments in deployment scripts against the current version's supported flags."],"exampleFix":"// before: typo in argument name\n//   garnet-server --potr 6379\n\n// after:\n//   garnet-server --port 6379","handlingStrategy":"try-catch","validationCode":"// Pre-validate by running a dry parse\nif (!ServerSettingsManager.TryParseCommandLineArguments(commandLineArgs, out _, out _, out var exitGracefully, out _))\n{\n    if (!exitGracefully)\n        Console.Error.WriteLine(\"Invalid command-line arguments. Run with --help for usage.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    server = new GarnetServer(commandLineArgs, loggerFactory);\n}\ncatch (GarnetException ex) when (ex.Message.Contains(\"initializing Garnet server\"))\n{\n    logger.LogError(ex, \"Garnet server failed to initialize due to invalid arguments. Check logs above.\");\n    return false;\n}","preventionTips":["Always read the log output above the exception — it contains the specific parse error.","Validate command-line arguments with --help before deploying.","Use deployment templates with pre-validated argument sets.","Test startup commands in staging before production."],"tags":["startup","command-line","configuration","argument-parsing"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}