{"record":{"id":"1921d18d36b192fa","repo":"Billionmail/BillionMail","slug":"rar-compression-failed-s-s","errorCode":null,"errorMessage":"rar compression failed: %s - %s","messagePattern":"rar compression failed: (.+?) - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/compress/rar.go","lineNumber":203,"sourceCode":"\t\t\treturn err\n\t\t}\n\n\t\t// make sure source exists\n\t\tif _, err := os.Stat(srcAbs); err != nil {\n\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>","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/compress/rar.go#L185-L221","documentation":"Compress runs `rar <args>` via exec.Command and captures combined stdout/stderr. If the rar process exits non-zero, this error wraps the exec error and the raw CLI output, indicating the rar tool itself failed (bad options, license prompt, unreadable source, password-protected archive, etc.).","triggerScenarios":"rar exits non-zero during RarUnpacker.Compress: invalid args, rar trial-license interactive prompt on stdin absence, permission-denied on source/output, disk full, or corrupt/locked sources.","commonSituations":"rar CLI on a headless server hitting the evaluation-license prompt; output directory not writable by the service user; volumes mounted read-only; password-protected inputs.","solutions":["Read the embedded output in the error message to identify the rar CLI failure reason","Ensure the process user can read sources and write the destination directory","Handle the rar evaluation license (purchase/register or use `rar a -y` with a valid license file rarreg.key)","Check free disk space on the destination volume","Consider using the pure-Go gzip unpacker or `zip` CLI to avoid the proprietary rar dependency"],"exampleFix":"// before\ncmd := exec.Command(\"rar\", args...)\n// after\ncmd := exec.Command(\"rar\", args...)\ncmd.Stdin = nil // avoid hanging on license prompt; check output in returned error and fix cause","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"rar\"); err != nil { return err }\nfor _, src := range srcList {\n\tif _, err := os.Stat(src); err != nil { return err }\n}\nif err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := r.Compress(dst, src...); err != nil {\n\tif strings.HasPrefix(err.Error(), \"rar compression failed:\") {\n\t\tlog.Printf(\"rar CLI failed: %v\", err) // output is embedded after the dash\n\t}\n}","preventionTips":["Log the embedded rar output to diagnose CLI failures quickly","Run as a user with read access to sources and write access to the output dir","Register a valid rar license to avoid evaluation prompts on headless hosts","Check disk space before long-running compression jobs"],"tags":["go","compression","rar","external-command","process-exit-error"],"backgroundTag":"external-command-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}