{"record":{"id":"941d4eec5a8fb006","repo":"IceWhaleTech/CasaOS","slug":"format-not-implemented","errorCode":null,"errorMessage":"format not implemented","messagePattern":"format not implemented","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/utils/file/file.go","lineNumber":429,"sourceCode":"\nfunc GetCompressionAlgorithm(t string) (string, archiver.Writer, error) {\n\tswitch t {\n\tcase \"zip\", \"\":\n\t\treturn \".zip\", archiver.NewZip(), nil\n\tcase \"tar\":\n\t\treturn \".tar\", archiver.NewTar(), nil\n\tcase \"targz\":\n\t\treturn \".tar.gz\", archiver.NewTarGz(), nil\n\tcase \"tarbz2\":\n\t\treturn \".tar.bz2\", archiver.NewTarBz2(), nil\n\tcase \"tarxz\":\n\t\treturn \".tar.xz\", archiver.NewTarXz(), nil\n\tcase \"tarlz4\":\n\t\treturn \".tar.lz4\", archiver.NewTarLz4(), nil\n\tcase \"tarsz\":\n\t\treturn \".tar.sz\", archiver.NewTarSz(), nil\n\tdefault:\n\t\treturn \"\", nil, errors.New(\"format not implemented\")\n\t}\n}\n\nfunc AddFile(ar archiver.Writer, path, commonPath string) error {\n\tinfo, err := os.Stat(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif !info.IsDir() && !info.Mode().IsRegular() {\n\t\treturn nil\n\t}\n\n\tfile, err := os.Open(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/IceWhaleTech/CasaOS/blob/0d3b2f444ec0193193cf03eef6d43c6e35b0183e/pkg/utils/file/file.go#L411-L447","documentation":"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.","triggerScenarios":"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').","commonSituations":"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.","solutions":["Whitelist and validate the format on the caller side before invoking the factory — restrict to the exact supported set.","Normalize input: strings.ToLower(strings.TrimSpace(format)) before the switch.","Extend the switch if you truly need the format (e.g. add a zstd archiver) rather than defaulting silently.","Return a user-facing message listing supported formats when validation fails."],"exampleFix":"// before\nar, ext, err := GetArchiver(userSuppliedFormat)\n\n// after\nvar supportedFormats = map[string]bool{\"zip\": true, \"tar\": true, \"targz\": true, \"tarbz2\": true, \"tarxz\": true, \"tarlz4\": true, \"tarsz\": true}\nformat := strings.ToLower(strings.TrimSpace(userSuppliedFormat))\nif !supportedFormats[format] {\n\treturn fmt.Errorf(\"unsupported archive format %q, supported: zip, tar, targz, tarbz2, tarxz, tarlz4, tarsz\", userSuppliedFormat)\n}\nar, ext, err := GetArchiver(format)","handlingStrategy":"validation","validationCode":"var supportedFormats = map[string]bool{\"zip\": true, \"gzip\": true, \"tar\": true, \"targz\": true, \"tarbz2\": true, \"tarxz\": true, \"tarlz4\": true, \"tarsz\": true}\n\nfunc IsValidFormat(f string) bool {\n\treturn supportedFormats[strings.ToLower(strings.TrimSpace(f))]\n}\n\nif !IsValidFormat(fmt_) { return fmt.Errorf(\"unsupported archive format %q\", fmt_) }","typeGuard":"func IsValidArchiveFormat(f string) bool {\n\t_, ok := map[string]struct{}{\"zip\": {}, \"gzip\": {}, \"tar\": {}, \"targz\": {}, \"tarbz2\": {}, \"tarxz\": {}, \"tarlz4\": {}, \"tarsz\": {}}[strings.ToLower(strings.TrimSpace(f))]\n\treturn ok\n}","tryCatchPattern":null,"preventionTips":["Restrict UI/API format choices to a server-side whitelist","Normalize (trim, lowercase) format input before the switch","Test the factory against every advertised format in unit tests"],"tags":["archive","validation","user-input","utils"],"backgroundTag":null,"analyzedSha":"0d3b2f444ec0193193cf03eef6d43c6e35b0183e","analyzedAt":"2026-08-15T13:27:57.821Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}