{"record":{"id":"94c4ed3104823529","repo":"microsoft/aspire","slug":"process-command-output-line-count-must-be-greater-than-zero","errorCode":null,"errorMessage":"Process command output line count must be greater than zero.","messagePattern":"Process command output line count must be greater than zero\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ResourceBuilderExtensions.cs","lineNumber":3331,"sourceCode":"\n    private static ProcessCommandOptions CreateProcessCommandOptions(ProcessCommandResultExportOptions? exportOptions)\n    {\n        var commandOptions = new ProcessCommandOptions();\n        if (exportOptions is null)\n        {\n            return commandOptions;\n        }\n\n        if (exportOptions.CommandOptions is { } commonOptions)\n        {\n            ApplyCommandOptions(commandOptions, commonOptions);\n        }\n\n        if (exportOptions.MaxOutputLineCount is { } maxOutputLineCount)\n        {\n            if (maxOutputLineCount <= 0)\n            {\n                throw new DistributedApplicationException(\"Process command output line count must be greater than zero.\");\n            }\n\n            commandOptions.MaxOutputLineCount = maxOutputLineCount;\n        }\n\n        if (exportOptions.DisplayImmediately is { } displayImmediately)\n        {\n            commandOptions.DisplayImmediately = displayImmediately;\n        }\n\n        // Some generated clients serialize default collection values as empty arrays. Treat an empty exported list as\n        // omitted so those clients preserve the default [0] success code.\n        if (exportOptions.SuccessExitCodes is { Count: > 0 } successExitCodes)\n        {\n            commandOptions.SuccessExitCodes = successExitCodes.ToArray();\n        }\n\n        return commandOptions;","sourceCodeStart":3313,"sourceCodeEnd":3349,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L3313-L3349","documentation":"When converting exported process-command options into internal ProcessCommandOptions, Aspire validates MaxOutputLineCount, which caps how many lines of process output are retained/returned. A value of zero or negative would make the bounded tail meaningless, so a DistributedApplicationException is thrown at command registration time.","triggerScenarios":"Call withProcessCommand (export path) with options where MaxOutputLineCount is set to 0 or a negative number; the exception is thrown synchronously while registering the command, not when the command runs.","commonSituations":"Config-driven option values where a config file or environment variable supplies 0 or -1 as a 'disabled' sentinel; string-to-number parsing producing 0 for empty values; copying defaults incorrectly between code and polyglot options.","solutions":["Set MaxOutputLineCount to a positive integer (e.g. 100).","Omit MaxOutputLineCount entirely to keep the default; do not use 0 as 'unlimited'.","Validate any user/config-supplied value before passing it into options (reject <= 0)."],"exampleFix":"// before\noptions.MaxOutputLineCount = int.Parse(config[\"MaxOutputLines\"]); // 0 when unset\n// after\nif (int.TryParse(config[\"MaxOutputLines\"], out var n) && n > 0)\n{\n    options.MaxOutputLineCount = n;\n}","handlingStrategy":"validation","validationCode":"if (options.MaxOutputLineCount is { } n && n <= 0)\n    throw new ArgumentOutOfRangeException(nameof(options.MaxOutputLineCount), n, \"Must be > 0.\");","typeGuard":"static bool IsValidLineCount(int? n) => n is null or > 0;","tryCatchPattern":"try { builder.WithProcessCommandExport(name, display, options); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"line count must be greater than zero\"))\n{ logger.LogError(ex, \"Fix MaxOutputLineCount in options for {Command}\", name); }","preventionTips":["Never use 0 as 'unlimited'; omit MaxOutputLineCount for defaults","Clamp or reject config-sourced values <= 0 before assignment","Guard against empty-string parses yielding 0"],"tags":["process-command","argument-validation","value-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}