{"record":{"id":"c95474d4fb27e0ce","repo":"hashicorp/packer","slug":"failed-to-run-os-detection-command-s","errorCode":null,"errorMessage":"failed to run OS detection command: %s","messagePattern":"failed to run OS detection command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/hcp-sbom/provisioner.go","lineNumber":384,"sourceCode":"\t}\n\n\t// Run detection command based on communicator\n\tvar cmd *packersdk.RemoteCmd\n\tif connType == \"winrm\" {\n\t\tcmd = &packersdk.RemoteCmd{\n\t\t\tCommand: \"echo %PROCESSOR_ARCHITECTURE%\",\n\t\t}\n\t} else {\n\t\tcmd = &packersdk.RemoteCmd{\n\t\t\tCommand: \"uname -s -m\",\n\t\t}\n\t}\n\n\tvar stdout bytes.Buffer\n\tcmd.Stdout = &stdout\n\n\tif err := comm.Start(ctx, cmd); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to run OS detection command: %s\", err)\n\t}\n\n\tcmd.Wait()\n\n\tif cmd.ExitStatus() != 0 {\n\t\treturn \"\", \"\", fmt.Errorf(\"OS detection command exited with status %d\", cmd.ExitStatus())\n\t}\n\n\toutput := strings.TrimSpace(stdout.String())\n\tlog.Printf(\"OS detection output: %s\", output)\n\n\t// Parse output\n\tvar osType, osArch string\n\tif connType == \"winrm\" {\n\t\tosType = \"Windows\"\n\t\tosArch = strings.ToLower(output) // AMD64, ARM64, etc.\n\t} else {\n\t\tparts := strings.Fields(output)","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/hcp-sbom/provisioner.go#L366-L402","documentation":"detectRemoteOS error when comm.Start(ctx, cmd) fails to launch the OS detection command ('uname -s -m' over SSH, 'echo %PROCESSOR_ARCHITECTURE%' over WinRM) on the remote machine. This indicates the communicator could not start the command at all (connection/protocol-level failure), as distinct from the command running and exiting non-zero.","triggerScenarios":"comm.Start returns an error in detectRemoteOS, reached from Provision when generatedData lacks usable OSType/OSArch — e.g. SSH session cannot allocate/start the remote command, WinRM command dispatch fails, or the connection dropped.","commonSituations":"SSH connection dropped or not fully established when the provisioner runs; WinRM endpoint misconfigured (port/auth/HTTPS); guest shell unavailable or restricted; firewall/timeout killing the session mid-build.","solutions":["Check communicator logs immediately before this error for the underlying SSH/WinRM cause.","Verify SSH/WinRM connectivity (ssh into the guest or test WinRM) with the same credentials the builder uses.","Increase communicator timeouts / add retry settings if the connection is flaky.","Note the build itself continues: Provision logs 'Failed to detect remote OS' and skips SBOM generation, so this is non-fatal to the image build."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check communicator reachability before the provisioner runs\nclient, err := ssh.Dial(\"tcp\", fmt.Sprintf(\"%s:%d\", host, port), sshConfig)\nif err != nil {\n\treturn fmt.Errorf(\"guest not reachable over SSH before OS detection: %w\", err)\n}\nsession, err := client.NewSession()\nif err != nil {\n\treturn fmt.Errorf(\"cannot open SSH session (command start would fail): %w\", err)\n}\nsession.Close()","typeGuard":null,"tryCatchPattern":"if err := provisioner.Provision(ctx, ui, comm, data); err != nil {\n\tif strings.Contains(err.Error(), \"failed to run OS detection command\") {\n\t\t// non-fatal for the build: log, check SSH/WinRM config, optionally retry\n\t\tui.Error(\"OS detection failed; skipping SBOM generation\")\n\t\treturn nil\n\t}\n\treturn err\n}","preventionTips":["Validate SSH/WinRM credentials, port, and host key settings in the builder config","Increase communicator timeouts on slow-booting guests","Verify the guest shell exists and is permitted for the login user","Remember Provision treats this as non-fatal (build continues without SBOM) — fix connectivity to restore SBOM generation"],"tags":["communicator","ssh","winrm","provisioner"],"backgroundTag":"remote-command-start-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"}