{"record":{"id":"789ac955c01fb382","repo":"vxcontrol/pentagi","slug":"failed-to-create-temporary-upload-file-w","errorCode":null,"errorMessage":"failed to create temporary upload file: %w","messagePattern":"failed to create temporary upload file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/flowfiles/files.go","lineNumber":326,"sourceCode":"\t\treturn nil, err\n\t}\n\tif !info.Mode().IsRegular() {\n\t\treturn nil, fmt.Errorf(\"'%s' is not a regular file\", filePath)\n\t}\n\n\treturn info, nil\n}\n\nfunc SaveUploadedFileToTemp(fh *multipart.FileHeader, dir string) (string, error) {\n\tsrc, err := fh.Open()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open uploaded file: %w\", err)\n\t}\n\tdefer src.Close()\n\n\tdst, err := os.CreateTemp(dir, \".upload-*\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create temporary upload file: %w\", err)\n\t}\n\ttmpPath := dst.Name()\n\tdefer dst.Close()\n\n\tif _, err := io.Copy(dst, src); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn \"\", fmt.Errorf(\"failed to write temporary upload file: %w\", err)\n\t}\n\tif err := dst.Chmod(0644); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn \"\", fmt.Errorf(\"failed to set temporary upload file permissions: %w\", err)\n\t}\n\n\treturn tmpPath, nil\n}\n\nfunc IsWithinDir(absPath, dir string) bool {\n\treturn strings.HasPrefix(","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/flowfiles/files.go#L308-L344","documentation":"SaveUploadedFileToTemp streams a multipart upload into a temp file created via os.CreateTemp(dir, \".upload-*\"). This error wraps the failure of that CreateTemp call, meaning no temp file could be created in the target directory. Since no file was created, nothing needs cleanup — only the wrapped OS error is propagated.","triggerScenarios":"Calling SaveUploadedFileToTemp(fh, dir) when: dir does not exist, the process lacks write permission on dir, dir points to a read-only filesystem (e.g. container rootfs), or the filesystem is full / inode-exhausted so CreateTemp's random-name retries all fail.","commonSituations":"Docker containers with read-only or tiny tmpfs mount points; the uploads directory deleted after image build; running as non-root user without ownership of the temp dir; disk-full on busy hosts after many uploads.","solutions":["Verify dir exists and is writable by the process user; run os.MkdirAll(dir, 0755) before calling SaveUploadedFileToTemp.","Check disk space (df) and inodes (df -i) on the volume backing dir.","If running in a container, confirm dir is on a writable volume, not a read-only rootfs; add a volume mount for the uploads path.","Fix filesystem ownership/permissions (chown/chmod) for the service account."],"exampleFix":"// before\ntmpPath, err := flowfiles.SaveUploadedFileToTemp(fh, cfg.UploadDir)\n// after\nif err := os.MkdirAll(cfg.UploadDir, 0o755); err != nil {\n    return fmt.Errorf(\"prepare upload dir: %w\", err)\n}\ntmpPath, err := flowfiles.SaveUploadedFileToTemp(fh, cfg.UploadDir)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(dir)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"upload dir %q missing: %w\", dir, err)\n}\nprobe, err := os.CreateTemp(dir, \".probe-*\")\nif err != nil {\n    return fmt.Errorf(\"upload dir %q not writable: %w\", dir, err)\n}\nprobe.Close(); os.Remove(probe.Name())","typeGuard":null,"tryCatchPattern":"tmpPath, err := flowfiles.SaveUploadedFileToTemp(fh, dir)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && (errors.Is(pe.Err, syscall.ENOSPC) || errors.Is(pe.Err, syscall.EACCES) || errors.Is(pe.Err, syscall.EROFS)) {\n        http.Error(w, \"storage temporarily unavailable\", http.StatusServiceUnavailable)\n        return\n    }\n    http.Error(w, \"upload failed\", http.StatusInternalServerError)\n    return\n}","preventionTips":["Create and permission-check the uploads directory at service startup, fail fast if not writable.","Mount uploads on a dedicated writable volume with adequate space in container deployments.","Monitor disk usage and alert before the volume fills."],"tags":["filesystem","io","upload","temp-file"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}