{"record":{"id":"3f5b8d96eff74875","repo":"pulumi/pulumi","slug":"parse-arguments-w","errorCode":null,"errorMessage":"parse arguments: %w","messagePattern":"parse arguments: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/do/do.go","lineNumber":112,"sourceCode":"\tvar dryrun bool\n\tvar showSecrets bool\n\tvar stateless bool\n\tvar output string\n\n\t// buildSubcommand returns the dynamically constructed subcommand along with a cleanup function that must be\n\t// deferred by the caller. The cleanup tears down the provider gRPC channel — running it as a defer inside\n\t// buildSubcommand would close the channel before the subcommand's RunE actually invokes the provider.\n\tbuildSubcommand := func(cmd *cobra.Command, args []string) (*cobra.Command, func(), error) {\n\t\t// We have to do our own flag parsing because we're dynamically building the CLI from provider schemas.\n\t\t// Parse the arguments so far, but don't error on unknown flags since those will be dynamically added by\n\t\t// provider plugins.\n\t\tflags := cmd.Flags()\n\t\tflags.ParseErrorsAllowlist.UnknownFlags = true\n\t\terr := flags.Parse(args)\n\t\t// We shouldn't ever see --help here\n\t\tcontract.Assertf(!errors.Is(err, pflag.ErrHelp), \"unexpected --help flag\")\n\t\tif err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"parse arguments: %w\", err)\n\t\t}\n\n\t\tif output != \"\" && output != \"default\" && output != \"json\" {\n\t\t\treturn nil, nil, fmt.Errorf(\"unsupported output format %q (supported: default, json)\", output)\n\t\t}\n\n\t\tpargs := flags.Args()\n\t\t// If we don't have any args and no package then this is just `pulumi do` so return nil and the caller handle\n\t\t// calling help.\n\t\tif len(pargs) == 0 && pkg == \"\" {\n\t\t\treturn nil, nil, nil\n\t\t}\n\n\t\t// If --package was passed use that, else set it based on the token\n\t\tif pkg == \"\" {\n\t\t\tpkg, _, _ = strings.Cut(pargs[0], \":\")\n\t\t}\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/do/do.go#L94-L130","documentation":"In the `pulumi do` command's RunFunc setup, command-line flag parsing errors (other than the explicitly allowed unknown flags and --help) are wrapped as 'parse arguments: %w'. The underlying pflag error names the specific bad flag or value.","triggerScenarios":"Passing an invalid value to a typed flag (e.g. non-integer to an int flag), or a malformed flag that is not covered by the unknown-flags allowlist, when invoking the internal `pulumi do` entry point.","commonSituations":"Typo'd flag names not exempted from the allowlist; scripts passing values of the wrong type; quoting errors turning one flag into garbage tokens.","solutions":["Read the wrapped pflag error to identify the offending flag and fix its value or spelling","Run with --help to list valid flags for the command","Quote arguments containing spaces or special characters in your script"],"exampleFix":"// before\npulumi do --timeout notanumber\n// after\npulumi do --timeout 300","handlingStrategy":"try-catch","validationCode":"// validate flag values before invoking, e.g.:\nif ! timeout.isdigit(): raise SystemExit('--timeout expects an integer')","typeGuard":null,"tryCatchPattern":"try { run(cmd) } catch (e) { if (e.message.startsWith('parse arguments:')) { console.error('bad flag:', e.cause ?? e.message); process.exit(2) } else throw e }","preventionTips":["Quote arguments with spaces or special characters in scripts","Check `--help` for exact flag names and expected value types","Keep flag builders typed/validated rather than raw string concatenation"],"tags":["cli","flag-parsing","arguments"],"backgroundTag":"flag-parse-error","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}