{"record":{"id":"ed51769fb1477c19","repo":"hashicorp/packer","slug":"failed-to-read-s-s","errorCode":null,"errorMessage":"failed to read %s: %s","messagePattern":"failed to read (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hcl2template/formatter.go","lineNumber":139,"sourceCode":"\t\treturn nil, fmt.Errorf(\"file %s is not a HCL file\", filename)\n\t}\n\n\tvar in io.Reader\n\tvar err error\n\n\tif filename == \"-\" {\n\t\tin = os.Stdin\n\t\tf.ShowDiff = false\n\t} else {\n\t\tin, err = os.Open(filename)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to open %s: %s\", filename, err)\n\t\t}\n\t}\n\n\tinSrc, err := io.ReadAll(in)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read %s: %s\", filename, err)\n\t}\n\n\t_, diags := f.parser.ParseHCL(inSrc, filename)\n\tif diags.HasErrors() {\n\t\treturn nil, multierror.Append(nil, diags.Errs()...)\n\t}\n\n\toutSrc := hclwrite.Format(inSrc)\n\n\tif bytes.Equal(inSrc, outSrc) {\n\t\tif filename == \"-\" {\n\t\t\t_, _ = f.Output.Write(outSrc)\n\t\t}\n\n\t\treturn nil, nil\n\t}\n\n\tif filename != \"-\" {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/hcl2template/formatter.go#L121-L157","documentation":"After opening the file, processFile reads it fully via io.ReadAll; an I/O failure at this stage (disk errors, reading a directory handle, device errors) yields 'failed to read %s: %s' wrapping the OS error.","triggerScenarios":"io.ReadAll failing inside processFile after a successful os.Open — typically reading a directory or special file that opened without error, or hardware/permission issues mid-read.","commonSituations":"Reading special files (/proc entries, device files) accidentally matched by globs; directories passed as paths on platforms where open succeeds; failing disks or network mounts dropping mid-read.","solutions":["Ensure the target is a regular file, not a directory or special file","Check the filesystem/mount is healthy and reachable","Re-run to rule out a transient I/O error and inspect the wrapped OS error text"],"exampleFix":"// before\npacker fmt /proc/self/cmdline\n// after\npacker fmt ./templates/build.pkr.hcl","handlingStrategy":"try-catch","validationCode":"info, err := os.Stat(path)\n// require err == nil && info.Mode().IsRegular()","typeGuard":null,"tryCatchPattern":"if err := f.FormatFile(path); err != nil {\n  if strings.Contains(err.Error(), \"failed to read\") { /* retry or report I/O issue */ }\n}","preventionTips":["Only pass regular files (Mode().IsRegular()) to the formatter","Avoid /proc, /sys, and device files","Retry once on transient I/O errors before failing"],"tags":["filesystem","io","formatter","read-error"],"backgroundTag":"file-read-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"}