{"record":{"id":"81b6ceded657015d","repo":"dgraph-io/badger","slug":"invalid-filename-s","errorCode":null,"errorMessage":"Invalid filename: %s","messagePattern":"Invalid filename: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"table/table.go","lineNumber":285,"sourceCode":"// deleting. Checksum for all blocks of table is verified based on value of chkMode.\nfunc OpenTable(mf *z.MmapFile, opts Options) (*Table, error) {\n\t// BlockSize is used to compute the approximate size of the decompressed\n\t// block. It should not be zero if the table is compressed.\n\tif opts.BlockSize == 0 && opts.Compression != options.None {\n\t\t_ = mf.Close(-1)\n\t\treturn nil, errors.New(\"Block size cannot be zero\")\n\t}\n\tfileInfo, err := mf.Fd.Stat()\n\tif err != nil {\n\t\tmf.Close(-1)\n\t\treturn nil, y.Wrap(err, \"\")\n\t}\n\n\tfilename := fileInfo.Name()\n\tid, ok := ParseFileID(filename)\n\tif !ok {\n\t\tmf.Close(-1)\n\t\treturn nil, fmt.Errorf(\"Invalid filename: %s\", filename)\n\t}\n\tt := &Table{\n\t\tMmapFile:   mf,\n\t\tid:         id,\n\t\topt:        &opts,\n\t\tIsInmemory: false,\n\t\ttableSize:  int(fileInfo.Size()),\n\t\tCreatedAt:  fileInfo.ModTime(),\n\t}\n\t// Caller is given one reference.\n\tt.ref.Store(1)\n\n\tif err := t.initBiggestAndSmallest(); err != nil {\n\t\t_ = mf.Close(-1)\n\t\treturn nil, y.Wrapf(err, \"failed to initialize table\")\n\t}\n\n\tif opts.ChkMode == options.OnTableRead || opts.ChkMode == options.OnTableAndBlockRead {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/table/table.go#L267-L303","documentation":"OpenTable derives the table ID from the mmap'd file's base name via ParseFileID. If the filename doesn't contain a parseable table ID (the expected 'NNNNNN.sst' / table-number format), OpenTable closes the file and returns 'Invalid filename: <name>'.","triggerScenarios":"Opening a mmap'd file that is not a badger table file — e.g. keylog/vlog files, temp files, lock files, files with unusual suffixes, or renamed tables — by passing it to OpenTable; pointing OpenTable at a file copied with a modified name (e.g. '000001.sst.bak' or 'table1.sst').","commonSituations":"Iterating a directory and opening every mmap-able file as a table instead of filtering *.sst; renaming or copying table files for backup/inspection with extra extensions; hand-edited or corrupted filenames; running OpenTable on files from a different badger component.","solutions":["Ensure the file name matches badger's table naming scheme (numeric ID + table extension) before calling OpenTable; only pass files matched by the table-id regex/glob","Rename the file back to its valid form (e.g. 000001.sst) if it was renamed for backup","Filter directory listings using table.ParseFileID or the table file pattern before constructing tables","Open the DB through badger.Open so only valid table files are opened"],"exampleFix":"// before\nmf, err := z.OpenMmapFile(\"000001.sst.bak\", ...) // invalid name\ntbl, err := table.OpenTable(mf, opts)\n// after\nid, ok := table.ParseFileID(\"000001.sst\")\nif !ok { return fmt.Errorf(\"not a table file\") }\ntbl, err := table.OpenTable(mf, opts)","handlingStrategy":"validation","validationCode":"if _, ok := table.ParseFileID(filepath.Base(path)); !ok {\n\treturn nil, fmt.Errorf(\"%s is not a badger table file\", path)\n}","typeGuard":"func isTableFile(name string) bool {\n\t_, ok := table.ParseFileID(name)\n\treturn ok\n}","tryCatchPattern":"tbl, err := table.OpenTable(mf, opts)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"Invalid filename:\") {\n\t\t_ = mf.Close(-1) // not a table file; skip it\n\t\treturn nil, err\n\t}\n\treturn nil, err\n}","preventionTips":["Filter directory entries with ParseFileID (or the *.sst pattern) before opening as tables","Never rename table files; if you must copy them, restore the exact original name","Skip temp/lock/vlog files when scanning a badger directory","Open DBs through badger.Open rather than manually opening mmap files"],"tags":["filesystem","filename","parsing"],"backgroundTag":"invalid-table-filename","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}