{"record":{"id":"ae669c85069e1294","repo":"microsoft/aspire","slug":"the-value-0-is-not-valid-for-1","errorCode":null,"errorMessage":"The value '{0}' is not valid for {1}.","messagePattern":"The value '(.+?)' is not valid for (.+?)\\.","errorType":"exception","errorClass":"NonInteractiveException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Interaction/ConsoleInteractionService.cs","lineNumber":829,"sourceCode":"    {\n        DisplayError(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NonInteractiveOptionRequired, symbolDisplayName));\n        throw new NonInteractiveException(symbolDisplayName);\n    }\n\n    internal void ValidateResolvedStringValue(string value, bool required, Func<string, ValidationResult>? validator, string symbolDisplayName)\n    {\n        if (required && string.IsNullOrEmpty(value))\n        {\n            ThrowNonInteractiveError(symbolDisplayName);\n        }\n\n        if (validator is not null)\n        {\n            var result = validator(value);\n            if (!result.Successful)\n            {\n                DisplayError(result.Message ?? string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NonInteractiveInvalidValue, value, symbolDisplayName));\n                throw new NonInteractiveException(symbolDisplayName);\n            }\n        }\n    }\n\n    [DoesNotReturn]\n    internal void ThrowNonInteractiveInvalidValue<T>(string value, string symbolDisplayName, IEnumerable<T> choices, Func<T, string> choiceFormatter) where T : notnull\n    {\n        DisplayError(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NonInteractiveInvalidValue, value, symbolDisplayName));\n        // Strip Spectre markup from each formatted choice so non-interactive callers see plain\n        // text. Some choice formatters intentionally include [bold]/[dim]/etc. tokens for the\n        // interactive multi-select renderer; those tokens would otherwise leak verbatim through\n        // DisplaySubtleMessage and confuse anyone diagnosing a typoed --option value.\n        var availableChoices = string.Join(\", \", choices.Select(c => StringUtils.RemoveMarkup(choiceFormatter(c))));\n        DisplaySubtleMessage(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NonInteractiveAvailableValues, availableChoices));\n        throw new NonInteractiveException(symbolDisplayName);\n    }\n\n    internal T MatchChoiceOrThrow<T>(string value, PromptBinding<string?> binding, IEnumerable<T> choices, Func<T, string> choiceFormatter) where T : notnull","sourceCodeStart":811,"sourceCodeEnd":847,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs#L811-L847","documentation":"When the CLI runs non-interactively (no TTY), ConsoleInteractionService validates each prompt-bound value with the symbol's validator. If the validator rejects the value, it displays this formatted message naming the value and the option's display name, then throws NonInteractiveException to abort the command instead of looping on a prompt that cannot be shown.","triggerScenarios":"Calling an Aspire CLI command non-interactively (e.g. piped stdin or CI) with an --option value that fails the symbol's validator function passed to the prompt/interaction API.","commonSituations":"CI scripts or shell pipelines passing typoed or malformed option values; validators added to prompts that existing scripts' values no longer satisfy; values containing characters the validator rejects.","solutions":["Fix the --option value passed on the command line so it passes the symbol's validator","Run the command interactively once to see which values are accepted, then reuse them in the script","Inspect the validator for the symbol to learn the accepted format"],"exampleFix":"// before\naspire add redis --name \"my cache!\"\n// after\naspire add redis --name myCache","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(value) || !allowedRegex.IsMatch(value))\n    throw new ArgumentException($\"'{value}' is not a valid value for the option.\");","typeGuard":null,"tryCatchPattern":"try { await cli.InvokeAsync(args); }\ncatch (NonInteractiveException ex) { logger.LogError(ex, \"Non-interactive value rejected: {Msg}\", ex.Message); }","preventionTips":["Validate option values in scripts before passing them to the CLI","Avoid running value-heavy prompts in CI; prefer flags with pre-checked values","After CLI upgrades, re-verify choice/validator constraints still accept your values"],"tags":["cli","non-interactive","validation"],"backgroundTag":"invalid-argument-value","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"}