{"record":{"id":"c209b660e453c9cf","repo":"hashicorp/packer","slug":"error-uploading-script-s-c209b6","errorCode":null,"errorMessage":"Error uploading script: %s","messagePattern":"Error uploading script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/windows-shell/provisioner.go","lineNumber":216,"sourceCode":"\t\t}\n\t\tcommand, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)\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\n\t\t// a single retryable function so that we don't end up with\n\t\t// the case that the upload succeeded, a restart is initiated,\n\t\t// and then the command is executed but the file doesn't exist\n\t\t// 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\n\t\t\tif err := comm.Upload(p.config.RemotePath, f, nil); 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})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Close the original file since we copied it\n\t\tf.Close()\n\n\t\tif err := p.config.ValidExitCode(cmd.ExitStatus()); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/windows-shell/provisioner.go#L198-L234","documentation":"Raised inside the retryable upload-and-run closure in Provision: after seeking the script file back to the start, comm.Upload pushes the script to the guest at p.config.RemotePath; if the communicator upload fails, the error is wrapped as \"Error uploading script: %s\". The retry.Config wrapper (StartRetryTimeout) re-runs the closure on failure, so this error surfaces only after retries are exhausted, meaning the guest communicator repeatedly refused or dropped the upload.","triggerScenarios":"Within retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run, f.Seek(0,0) succeeds but comm.Upload(p.config.RemotePath, f, nil) returns an error every attempt — unreachable guest, WinRM/SSH session drops mid-transfer, guest disk full, or remote path not writable. provisioner.go:210-219; the final wrapped error is returned after the retry timeout elapses.","commonSituations":"Windows guest rebooted or network blipped during provisioning so WinRM dropped; guest disk full preventing the temp upload; WinRM timeout too small for large scripts over slow links; communicator credentials/HTTPS misconfiguration; RemotePath colliding with an unwritable directory.","solutions":["Increase winrm_timeout / ssh timeouts and StartRetryTimeout so slow or intermittently flaky guest connections survive the retries.","Verify the guest communicator is healthy at that point in the build (no restart in progress; ping/WinRM reachable) and fix any windows-restart/pause ordering.","Check the guest's free disk space and that RemotePath's directory (usually a temp path) is writable.","Inspect the wrapped error in the message for the concrete cause (e.g. 'unknown error post-upload', timeout, auth) and address accordingly."],"exampleFix":"// before (HCL2): short WinRM timeout drops uploads\nwinrm_timeout = \"10m\"\n// after\nwinrm_timeout = \"1h\"\nwinrm_use_ntlm = true  // if flaky negotiation was the cause","handlingStrategy":"retry","validationCode":"// pre-flight: verify communicator reachability before provisioning phase\nif err := testWinRm(host, user, pass, timeout); err != nil {\n    return fmt.Errorf(\"guest unreachable before upload: %w\", err)\n}\n// and ensure guest disk space via an earlier provisioner step","typeGuard":null,"tryCatchPattern":"err := retry.Config{StartTimeout: 30 * time.Minute}.Run(ctx, func(ctx context.Context) error {\n    if err := comm.Upload(remote, f, nil); err != nil {\n        return fmt.Errorf(\"Error uploading script: %w\", err) // retried\n    }\n    return nil\n})\nif err != nil { return fmt.Errorf(\"upload failed after retries: %w\", err) }","preventionTips":["Set generous winrm_timeout/ssh timeouts relative to script size and link speed.","Avoid scheduling restarts (windows-restart) immediately before large uploads without pause_before.","Monitor guest disk usage; clean temp before uploads.","Read the wrapped cause in the message to distinguish network vs auth vs disk problems."],"tags":["provisioner","windows","upload","communicator","retry"],"backgroundTag":"script-upload-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"}