IceWhaleTech/CasaOS · error

format not implemented

Error message

format not implemented

What it means

The archive-format factory in GetArchiver rejected the requested format string because it matches none of the supported cases (tar, targz, tarbz2, tarxz, tarlz4, tarsz, and the earlier zip/gzip cases). The caller asked for a compression/archival format this build does not implement, so no archiver.Writer could be produced.

Source

Thrown at pkg/utils/file/file.go:429

func GetCompressionAlgorithm(t string) (string, archiver.Writer, error) {
	switch t {
	case "zip", "":
		return ".zip", archiver.NewZip(), nil
	case "tar":
		return ".tar", archiver.NewTar(), nil
	case "targz":
		return ".tar.gz", archiver.NewTarGz(), nil
	case "tarbz2":
		return ".tar.bz2", archiver.NewTarBz2(), nil
	case "tarxz":
		return ".tar.xz", archiver.NewTarXz(), nil
	case "tarlz4":
		return ".tar.lz4", archiver.NewTarLz4(), nil
	case "tarsz":
		return ".tar.sz", archiver.NewTarSz(), nil
	default:
		return "", nil, errors.New("format not implemented")
	}
}

func AddFile(ar archiver.Writer, path, commonPath string) error {
	info, err := os.Stat(path)
	if err != nil {
		return err
	}

	if !info.IsDir() && !info.Mode().IsRegular() {
		return nil
	}

	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()

View on GitHub (pinned to 0d3b2f444e)

Solutions

  1. Whitelist and validate the format on the caller side before invoking the factory — restrict to the exact supported set.
  2. Normalize input: strings.ToLower(strings.TrimSpace(format)) before the switch.
  3. Extend the switch if you truly need the format (e.g. add a zstd archiver) rather than defaulting silently.
  4. Return a user-facing message listing supported formats when validation fails.

Example fix

// before
ar, ext, err := GetArchiver(userSuppliedFormat)

// after
var supportedFormats = map[string]bool{"zip": true, "tar": true, "targz": true, "tarbz2": true, "tarxz": true, "tarlz4": true, "tarsz": true}
format := strings.ToLower(strings.TrimSpace(userSuppliedFormat))
if !supportedFormats[format] {
	return fmt.Errorf("unsupported archive format %q, supported: zip, tar, targz, tarbz2, tarxz, tarlz4, tarsz", userSuppliedFormat)
}
ar, ext, err := GetArchiver(format)
Defensive patterns

Strategy: validation

Validate before calling

var supportedFormats = map[string]bool{"zip": true, "gzip": true, "tar": true, "targz": true, "tarbz2": true, "tarxz": true, "tarlz4": true, "tarsz": true}

func IsValidFormat(f string) bool {
	return supportedFormats[strings.ToLower(strings.TrimSpace(f))]
}

if !IsValidFormat(fmt_) { return fmt.Errorf("unsupported archive format %q", fmt_) }

Type guard

func IsValidArchiveFormat(f string) bool {
	_, ok := map[string]struct{}{"zip": {}, "gzip": {}, "tar": {}, "targz": {}, "tarbz2": {}, "tarxz": {}, "tarlz4": {}, "tarsz": {}}[strings.ToLower(strings.TrimSpace(f))]
	return ok
}

Prevention

When it happens

Trigger: Calling the archiver factory with an unrecognized format string — e.g. '7z', 'rar', 'zst', 'zip64', an empty string, or a value with different casing/whitespace ('TarGz' vs 'targz').

Common situations: User-supplied format passed through from a UI dropdown or API without validation; a client upgraded expectations (e.g. asks for 'tar.zst') not matched by this library version; typo or locale formatting in the format parameter.

Related errors


AI-assisted analysis of IceWhaleTech/CasaOS@0d3b2f444e (2026-08-15). Data as JSON: /api/errors/941d4eec5a8fb006. Report an issue: GitHub.