{"record":{"id":"19c9db95af191be3","repo":"hashicorp/packer","slug":"error-processing-command-s","errorCode":null,"errorMessage":"Error processing command: %s","messagePattern":"Error processing command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/powershell/provisioner.go","lineNumber":381,"sourceCode":"\n\t\tlog.Printf(\"Opening %s for reading\", path)\n\t\tfi, err := os.Stat(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error stating powershell script: %s\", err)\n\t\t}\n\t\tif os.IsPathSeparator(p.config.RemotePath[len(p.config.RemotePath)-1]) {\n\t\t\t// path is a directory\n\t\t\tp.config.RemotePath += filepath.Base(fi.Name())\n\t\t}\n\t\tf, err := os.Open(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error opening powershell script: %s\", err)\n\t\t}\n\t\tdefer f.Close()\n\n\t\tcommand, err := p.createCommandText()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error processing command: %s\", err)\n\t\t}\n\n\t\t// Upload the file and run the command. Do this in the context of a\n\t\t// single retryable function so that we don't end up with the case\n\t\t// that the upload succeeded, a restart is initiated, and then the\n\t\t// command is executed but the file doesn't exist any longer.\n\t\tvar cmd *packersdk.RemoteCmd\n\t\terr = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n\t\t\tif _, err := f.Seek(0, 0); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif err := comm.Upload(p.config.RemotePath, f, &fi); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Error uploading script: %s\", err)\n\t\t\t}\n\n\t\t\tcmd = &packersdk.RemoteCmd{Command: command}\n\t\t\treturn cmd.RunWithUi(ctx, comm, ui)\n\t\t})","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/powershell/provisioner.go#L363-L399","documentation":"Provision calls p.createCommandText() to build the remote PowerShell command line (which interpolates environment vars, elevated-run settings, and generated data into the command). Any failure inside that rendering returns \"Error processing command: %s\", aborting before upload/execution.","triggerScenarios":"Provision called when createCommandText's interpolate.Render fails — typically invalid template syntax in env vars, elevated_user/elevated_password, or incompatible generated-data usage in the command template.","commonSituations":"Environment variable values containing Go-template '{{' sequences; references to build-generated data (e.g. {{ .ID }}) in positions where the data isn't present; malformed quoting in elevated_password causing render errors; Packer version differences in available context keys.","solutions":["Read the wrapped cause and fix the offending template expression in environment_vars or related config.","Escape literal '{{'/'}}' sequences in variable values ({{`{{`}}) so they are not parsed as Go templates.","Only reference generated data keys documented for your Packer version.","Bisect by simplifying environment_vars/elevated settings until the render succeeds, then restore pieces one at a time."],"exampleFix":"// before\nenvironment_vars = [\"HOST={{ .IP }}\"]  // .IP not in context\n// after\nenvironment_vars = [\"HOST={{ build `Name` }}\"]","handlingStrategy":"try-catch","validationCode":"// Before building, sanity-check env var values for Go-template syntax\nfor _, kv := range cfg.Vars {\n    if strings.Contains(kv, \"{{\") && !strings.Contains(kv, \"{{ `\") {\n        log.Printf(\"env var %q contains interpolation; verify keys exist in generated data\", kv)\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go\nerr := prov.Provision(ctx, ui, comm, genData)\nif err != nil && strings.Contains(err.Error(), \"Error processing command\") {\n    fmt.Fprintf(os.Stderr, \"command rendering failed: %v\\n\", err)\n    // simplify environment_vars / elevated settings, escape {{ }}, retry\n}","preventionTips":["Escape literal Go-template braces in variable values ({{`{{`}}).","Only interpolate generated-data keys documented for your Packer version.","Validate templates (`packer validate`) before full builds to surface render errors early.","Test elevated_user/elevated_password quoting separately when using elevated runs."],"tags":["powershell","provisioner","template-interpolation","runtime"],"backgroundTag":"template-render-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}