{"record":{"id":"c75c8af320da4873","repo":"hashicorp/packer","slug":"failed-to-parse-os-detection-output-s","errorCode":null,"errorMessage":"failed to parse OS detection output: %s","messagePattern":"failed to parse OS detection output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/hcp-sbom/provisioner.go","lineNumber":414,"sourceCode":"\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)\n\t\tif len(parts) >= 2 {\n\t\t\tosType = parts[0] // Linux, Darwin, FreeBSD, etc.\n\t\t\tosArch = parts[1] // x86_64, aarch64, etc.\n\t\t} else if len(parts) == 1 {\n\t\t\t// Some systems might only return one value\n\t\t\tosType = parts[0]\n\t\t\tosArch = \"unknown\"\n\t\t}\n\t}\n\n\tif osType == \"\" || osArch == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to parse OS detection output: %s\", output)\n\t}\n\n\t// Store in generatedData for potential reuse\n\tgeneratedData[\"OSType\"] = osType\n\tgeneratedData[\"OSArch\"] = osArch\n\n\treturn osType, osArch, nil\n}\n\n// getUserDestination determines and returns the destination path for the user SBOM file.\nfunc (p *Provisioner) getUserDestination() (string, error) {\n\tdst := p.config.Destination\n\n\t// Check if the destination exists and determine its type\n\tinfo, err := os.Stat(dst)\n\tif err == nil {\n\t\tif info.IsDir() {\n\t\t\t// If the destination is a directory, create a temporary file inside it","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/hcp-sbom/provisioner.go#L396-L432","documentation":"After the OS-detection command succeeds, detectRemoteOS parses its trimmed stdout. On non-WinRM targets it expects one or two whitespace-separated fields (OS type, optional architecture); if the output is empty or unparseable such that osType or osArch remains empty, the provisioner returns this error with the raw output for debugging. Typically it means the command produced no usable stdout despite exiting 0.","triggerScenarios":"`uname -s -m` exits 0 but prints nothing to the captured stdout (output redirected, stdout wiring lost, cmd.Wait returning before output is fully captured), or prints only whitespace; for WinRM, output that lowercases to an empty string.","commonSituations":"Custom/busybox shells emitting a login banner but no command output; a communicator adapter that drops RemoteCmd.Stdout; SELinux or sandboxing blocking output; guest with locale/encoding wrappers that swallow stdout; using an exotic communicator whose ExitStatus is 0 while no data was streamed.","solutions":["Run `uname -s -m` interactively on the guest with the same user and confirm two fields (e.g. `Linux x86_64`) are printed.","Pre-set OSType/OSArch via the build's generated data (e.g. a datasource or builder exposing them) so detectRemoteOS short-circuits and never parses stdout.","Check the Packer log line `OS detection output: ...` — it shows exactly what stdout was captured; fix whatever blanks it (shell profile echo redirections, aliases).","Retry with a plain POSIX shell (ssh_username account with /bin/sh default) to rule out shell-init interference.","If it reproduces on a known-good guest, report the communicator (plugin) version — stdout capture may be broken in that communicator."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Verify manually what the provisioner will see:\n// out=$(ssh user@host 'uname -s -m'); echo \"[$out]\"  # expect two fields, non-empty","typeGuard":"// Post-condition check before relying on parsed values\nfunc validOSDetection(osType, osArch string) bool {\n    return osType != \"\" && osArch != \"\"\n}","tryCatchPattern":"osType, osArch, err := p.detectRemoteOS(ctx, ui, comm, generatedData)\nif err != nil {\n    ui.Warn(\"OS detection failed, defaulting to linux/amd64\")\n    osType, osArch = \"Linux\", \"x86_64\" // fallback\n}","preventionTips":["Set OSType/OSArch via generated data to bypass stdout parsing","Check the 'OS detection output:' log line to see what stdout was captured","Remove shell-profile echo/redirection that clobbers command stdout","Use a standard POSIX shell account for the communicator","Pin a communicator plugin version known to capture RemoteCmd.Stdout correctly"],"tags":["provisioner","os-detection","parsing","stdout","ssh"],"backgroundTag":"command-output-parse-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"}