{"record":{"id":"02cbbff9b4e0250c","repo":"Billionmail/BillionMail","slug":"rar-file-was-not-created-successfully","errorCode":null,"errorMessage":"rar file was not created successfully","messagePattern":"rar file was not created successfully","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/compress/rar.go","lineNumber":208,"sourceCode":"\t\t\treturn fmt.Errorf(\"source file/directory does not exist: %s\", src)\n\t\t}\n\n\t\t// add source to arguments\n\t\targs = append(args, srcAbs)\n\t}\n\n\t// create command\n\tcmd := exec.Command(\"rar\", args...)\n\n\t// run command\n\toutput, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"rar compression failed: %s - %s\", err, string(output))\n\t}\n\n\t// verify the file was created\n\tif _, err := os.Stat(dstAbs); err != nil {\n\t\treturn errors.New(\"rar file was not created successfully\")\n\t}\n\n\treturn nil\n}\n\n// Unrar rar decompression\n// @author <2024-06-09>\nfunc Unrar(src, dst string) error {\n\treturn defaultRarUnpacker.Decompress(src, dst)\n}\n\n// Rar compresses files or directories into a rar archive\n// @author <2024-06-09>\nfunc Rar(dst string, srcList ...string) error {\n\treturn defaultRarUnpacker.Compress(dst, srcList...)\n}\n\n// UnrarWithExternalCommand decompresses a rar file using external rar command","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/compress/rar.go#L190-L226","documentation":"After the rar CLI reports success, Compress double-checks the archive file actually exists at dstAbs via os.Stat. If it does not, it returns this error — meaning rar exited 0 but produced no file at the expected absolute destination (e.g. rar wrote elsewhere due to relative-path cwd differences or silently skipped creating output).","triggerScenarios":"RarUnpacker.Compress where rar returned success but os.Stat(dstAbs) fails: destination directory does not exist, permission issues, rar placed output in its own cwd, or a race deleted the file.","commonSituations":"Passing a dst whose parent directory was never created (os.MkdirAll missing); service running with a different cwd so a relative rar output path diverges; read-only mounts where rar fails silently.","solutions":["Create the destination directory first (os.MkdirAll(filepath.Dir(dstAbs), 0755))","Pass an absolute destination path so rar and the Stat check agree","Confirm the service user has write permission on the destination directory","Capture rar's output (add verbose flags) to see where the archive was actually written"],"exampleFix":"// before\nerr := r.Compress(\"backups/app.rar\", src)\n// after\nos.MkdirAll(\"backups\", 0755)\nabs, _ := filepath.Abs(\"backups/app.rar\")\nerr := r.Compress(abs, src)","handlingStrategy":"validation","validationCode":"dstAbs, _ := filepath.Abs(dst)\nif err := os.MkdirAll(filepath.Dir(dstAbs), 0755); err != nil { return err }\nif _, err := os.Stat(filepath.Dir(dstAbs)); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := r.Compress(dst, src...); err != nil && err.Error() == \"rar file was not created successfully\" {\n\t// verify parent dir exists/writable and that dst was an absolute path, then retry once\n}","preventionTips":["Always create the destination directory (os.MkdirAll) before compressing","Pass absolute destination paths so rar and the existence check agree","Confirm the service user can write to the destination directory","Avoid cleaning up the destination path concurrently with the compression job"],"tags":["go","compression","rar","file-not-found","external-command"],"backgroundTag":"expected-output-file-missing","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}