{"record":{"id":"c670f629636b7e59","repo":"OpenNHP/opennhp","slug":"could-not-get-file-info-v","errorCode":null,"errorMessage":"could not get file info: %v","messagePattern":"could not get file info: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/db/utils.go","lineNumber":212,"sourceCode":"\thttpHost := fmt.Sprintf(\"http://%s/\", a.GetServerPeer().Host())\n\ttestReq, err := http.Get(httpHost) //nolint:gosec // G107: URL constructed from configured server peer\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif testReq.StatusCode == http.StatusBadRequest {\n\t\thttpHost = fmt.Sprintf(\"https://%s/\", a.GetServerPeer().Host())\n\t}\n\n\tfile, err := os.Open(filePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"could not open file: %v\", err)\n\t}\n\tdefer file.Close()\n\n\tfileInfo, err := file.Stat()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"could not get file info: %v\", err)\n\t}\n\n\t// create upload progress\n\tprogress := &UploadProgress{\n\t\tTotalSize: fileInfo.Size(),\n\t}\n\n\tstartTime := time.Now()\n\n\tbody := &bytes.Buffer{}\n\twriter := multipart.NewWriter(body)\n\n\tpart, err := writer.CreateFormFile(\"file\", filepath.Base(filePath))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"could not create form file: %v\", err)\n\t}\n\n\tprogressReader := &ProgressReader{","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/db/utils.go#L194-L230","documentation":"After opening the file, UploadFileToNHPServer calls file.Stat() to learn the total size for upload progress tracking. The error 'could not get file info: %v' wraps a Stat failure on an already-open file descriptor. On Linux this usually fails because the file was truncated/removed mid-flight, or on exotic filesystems where fstat is unsupported.","triggerScenarios":"Calling UploadFileToNHPServer on a file that is deleted or truncated between os.Open and file.Stat(); or Stat failing on special/character devices or FUSE mounts that reject fstat.","commonSituations":"A cleanup job or another process removes the file during upload startup; the path points at /dev/stdin or a pipe where size is undefined; a network filesystem that errors on fstat.","solutions":["Ensure no external process deletes or truncates the file during upload","Point the upload at a regular file on a local filesystem instead of a pipe/device","Re-run the upload; transient FUSE/NFS stat errors are usually momentary","Check filesystem health (dmesg for I/O errors) if persistent"],"exampleFix":"// before\n_, err = udpDevice.UploadFileToNHPServer(ztdoPath)\n// after\ninfo, err := os.Stat(ztdoPath)\nif err != nil || !info.Mode().IsRegular() {\n    return fmt.Errorf(\"%s is not a readable regular file\", ztdoPath)\n}\n_, err = udpDevice.UploadFileToNHPServer(ztdoPath)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil {\n    return fmt.Errorf(\"cannot stat %s: %w\", path, err)\n}\nif !info.Mode().IsRegular() {\n    return fmt.Errorf(\"%s is not a regular file; fstat size may be unavailable\", path)\n}","typeGuard":"func isStattable(path string) bool {\n    _, err := os.Stat(path)\n    return err == nil\n}","tryCatchPattern":"url, err := dev.UploadFileToNHPServer(filePath)\nif err != nil {\n    if strings.Contains(err.Error(), \"could not get file info\") {\n        return fmt.Errorf(\"file changed or filesystem rejected stat on %s: %w\", filePath, err)\n    }\n    return err\n}","preventionTips":["Freeze the file (no concurrent writers/deleters) during upload","Prefer local filesystems over FUSE/network mounts for upload sources","Check dmesg for I/O errors if stat failures recur","Avoid uploading from /dev/stdin or pipes"],"tags":["go","filesystem","stat","file-upload"],"backgroundTag":"file-read-failed","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}