{"record":{"id":"6a3d9c428f780dd4","repo":"Billionmail/BillionMail","slug":"unrar-command-not-found-please-install-it-first","errorCode":null,"errorMessage":"unrar command not found, please install it first","messagePattern":"unrar command not found, please install it first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/compress/rar.go","lineNumber":232,"sourceCode":"// 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\n// This is an alternative method using the external rar command\nfunc UnrarWithExternalCommand(src, dst string) error {\n\t// check if 'unrar' command exists\n\t_, err := exec.LookPath(\"unrar\")\n\tif err != nil {\n\t\treturn errors.New(\"unrar command not found, please install it first\")\n\t}\n\n\t// get absolute paths\n\tsrcAbs, err := filepath.Abs(src)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdstAbs, err := filepath.Abs(dst)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// ensure destination directory exists\n\tif err := os.MkdirAll(dstAbs, 0755); err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/compress/rar.go#L214-L250","documentation":"UnrarWithExternalCommand extracts rar archives by invoking the external 'unrar' CLI. It first runs exec.LookPath(\"unrar\"); when the binary is missing from PATH it returns this error without attempting extraction. Unlike compression, the underlying Go rar library only reads archives, but this function specifically depends on the external tool being present.","triggerScenarios":"Calling UnrarWithExternalCommand(src, dst) on hosts where unrar is not installed (minimal Docker images, CI runners, Windows without UnRAR.exe on PATH).","commonSituations":"Alpine/slim images lacking unrar; PATH not including /usr/local/bin in systemd or docker exec contexts; confusing rar (compressor) with unrar (extractor) — installing one does not provide the other.","solutions":["Install unrar (apt-get install unrar / apk add unrar / UnRAR for Windows) and verify with `which unrar`","Add unrar to the deployment Dockerfile","Use RarUnpacker's built-in Decompress (pure-Go read) instead of the external-command variant","Pre-check exec.LookPath(\"unrar\") at service startup and fail fast with a clear setup message"],"exampleFix":"// before\ncmd := exec.Command(\"unrar\", \"x\", \"-o+\", src, dst)\n// after (Dockerfile)\nRUN apt-get update && apt-get install -y --no-install-recommends unrar && rm -rf /var/lib/apt/lists/*","handlingStrategy":"fallback","validationCode":"if _, err := exec.LookPath(\"unrar\"); err != nil {\n\treturn fmt.Errorf(\"unrar is not installed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := UnrarWithExternalCommand(src, dst); err != nil && strings.Contains(err.Error(), \"unrar command not found\") {\n\t// fall back to the built-in pure-Go Decompress or install unrar\n}","preventionTips":["Install unrar in every environment that runs extraction (including Docker images)","Prefer the built-in pure-Go Decompress to drop the external dependency","Probe exec.LookPath(\"unrar\") at service startup","Keep PATH configuration consistent between shells, systemd, and containers"],"tags":["go","compression","rar","missing-binary","environment"],"backgroundTag":"missing-external-command","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"}