Billionmail/BillionMail · error

rar file was not created successfully

Error message

rar file was not created successfully

What it means

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).

Source

Thrown at core/internal/service/compress/rar.go:208

			return fmt.Errorf("source file/directory does not exist: %s", src)
		}

		// add source to arguments
		args = append(args, srcAbs)
	}

	// create command
	cmd := exec.Command("rar", args...)

	// run command
	output, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("rar compression failed: %s - %s", err, string(output))
	}

	// verify the file was created
	if _, err := os.Stat(dstAbs); err != nil {
		return errors.New("rar file was not created successfully")
	}

	return nil
}

// Unrar rar decompression
// @author <2024-06-09>
func Unrar(src, dst string) error {
	return defaultRarUnpacker.Decompress(src, dst)
}

// Rar compresses files or directories into a rar archive
// @author <2024-06-09>
func Rar(dst string, srcList ...string) error {
	return defaultRarUnpacker.Compress(dst, srcList...)
}

// UnrarWithExternalCommand decompresses a rar file using external rar command

View on GitHub (pinned to fc36c76c05)

Solutions

  1. Create the destination directory first (os.MkdirAll(filepath.Dir(dstAbs), 0755))
  2. Pass an absolute destination path so rar and the Stat check agree
  3. Confirm the service user has write permission on the destination directory
  4. Capture rar's output (add verbose flags) to see where the archive was actually written

Example fix

// before
err := r.Compress("backups/app.rar", src)
// after
os.MkdirAll("backups", 0755)
abs, _ := filepath.Abs("backups/app.rar")
err := r.Compress(abs, src)
Defensive patterns

Strategy: validation

Validate before calling

dstAbs, _ := filepath.Abs(dst)
if err := os.MkdirAll(filepath.Dir(dstAbs), 0755); err != nil { return err }
if _, err := os.Stat(filepath.Dir(dstAbs)); err != nil { return err }

Try / catch

if err := r.Compress(dst, src...); err != nil && err.Error() == "rar file was not created successfully" {
	// verify parent dir exists/writable and that dst was an absolute path, then retry once
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/02cbbff9b4e0250c. Report an issue: GitHub.