{"record":{"id":"515e7aeb38281a82","repo":"golang/go","slug":"archive-tar-unknown-file-mode-v","errorCode":null,"errorMessage":"archive/tar: unknown file mode %v","messagePattern":"archive/tar: unknown file mode (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/archive/tar/common.go","lineNumber":679,"sourceCode":"\t\th.Size = fi.Size()\n\tcase fi.IsDir():\n\t\th.Typeflag = TypeDir\n\t\th.Name += \"/\"\n\tcase fm&fs.ModeSymlink != 0:\n\t\th.Typeflag = TypeSymlink\n\t\th.Linkname = link\n\tcase fm&fs.ModeDevice != 0:\n\t\tif fm&fs.ModeCharDevice != 0 {\n\t\t\th.Typeflag = TypeChar\n\t\t} else {\n\t\t\th.Typeflag = TypeBlock\n\t\t}\n\tcase fm&fs.ModeNamedPipe != 0:\n\t\th.Typeflag = TypeFifo\n\tcase fm&fs.ModeSocket != 0:\n\t\treturn nil, fmt.Errorf(\"archive/tar: sockets not supported\")\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"archive/tar: unknown file mode %v\", fm)\n\t}\n\tif fm&fs.ModeSetuid != 0 {\n\t\th.Mode |= c_ISUID\n\t}\n\tif fm&fs.ModeSetgid != 0 {\n\t\th.Mode |= c_ISGID\n\t}\n\tif fm&fs.ModeSticky != 0 {\n\t\th.Mode |= c_ISVTX\n\t}\n\t// If possible, populate additional fields from OS-specific\n\t// FileInfo fields.\n\tif sys, ok := fi.Sys().(*Header); ok {\n\t\t// This FileInfo came from a Header (not the OS). Use the\n\t\t// original Header to populate all remaining fields.\n\t\th.Uid = sys.Uid\n\t\th.Gid = sys.Gid\n\t\th.Uname = sys.Uname","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/archive/tar/common.go#L661-L697","documentation":"Returned by tar.FileInfoHeader (common.go:679) as the default case when the os.FileInfo mode bits do not match any recognized type: regular file, dir, symlink, device (char/block), fifo, or socket. It signals a mode bit combination the tar package cannot map to a USTAR type flag.","triggerScenarios":"Passing an FileInfo whose mode is the zero value (no type bits set), or an irregular/typed file from a non-unix filesystem (e.g., Windows reparse points, Plan 9 special files) where ModeType bits are unset or unexpected.","commonSituations":"Archiving files reported by a custom/fs.FS that returns plain modes without a type bit; Windows files without ModeDir/ModeSymlink set; synthetic FileInfo from tests; filesystems reporting ModeIrregular only.","solutions":["Inspect the offending mode value printed in the error to see which bits are set.","Pre-classify entries: map unknown types to TypeReg or skip them before calling FileInfoHeader.","If walking a real unix tree, ensure you use os.Stat (not Lstat-with-odd-results) so type bits are populated.","On Windows/Plan9, convert reparse/special files to a representable type or omit them."],"exampleFix":"// before\nh, err := tar.FileInfoHeader(info, link) // unknown file mode %v\n\n// after\nmode := info.Mode()\nswitch {\ncase mode.IsRegular():\n    h, err = tar.FileInfoHeader(info, link)\ncase mode&fs.ModeIrregular != 0:\n    h, err = tar.FileInfoHeader SyntheticRegular(info) // or skip\ndefault:\n    h, err = tar.FileInfoHeader(info, link)\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func archivableMode(m fs.FileMode) bool {\n    switch {\n    case m.IsRegular(), m.IsDir():\n        return true\n    case m&fs.ModeSymlink != 0,\n         m&fs.ModeDevice != 0,\n         m&fs.ModeNamedPipe != 0,\n         m&fs.ModeSocket != 0:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Inspect the mode value in the error to identify the unknown type.","Pre-map unknown/irregular types to TypeReg or skip them.","Use os.Stat so type bits are populated on unix."],"tags":["archive","tar","filesystem","file-mode","type-flag"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}