{"record":{"id":"d30b0df44897d09c","repo":"litedb-org/LiteDB","slug":"0-d30b0d","errorCode":"0","errorMessage":"Unknow file format in $file: `{format}`","messagePattern":"Unknow file format in \\$file: `(.+?)`","errorType":"exception","errorClass":"LiteException","httpStatus":null,"severity":"error","filePath":"LiteDB/Engine/SystemCollections/SysFile.cs","lineNumber":32,"sourceCode":"        {\n            [\"json\"] = new SysFileJson(),\n            [\"csv\"] = new SysFileCsv()\n        };\n\n        public SysFile() : base(\"$file\")\n        {\n        }\n\n        public override IEnumerable<BsonDocument> Input(BsonValue options)\n        {\n            var format = this.GetFormat(options);\n\n            if (_formats.TryGetValue(format, out var factory))\n            {\n                return factory.Input(options);\n            }\n\n            throw new LiteException(0, $\"Unknow file format in $file: `{format}`\");\n        }\n\n        public override int Output(IEnumerable<BsonDocument> source, BsonValue options)\n        {\n            var format = this.GetFormat(options);\n\n            if (_formats.TryGetValue(format, out var factory))\n            {\n                return factory.Output(source, options);\n            }\n\n            throw new LiteException(0, $\"Unknow file format in $file: `{format}`\");\n        }\n\n        private string GetFormat(BsonValue options)\n        {\n            var filename = GetOption(options, \"filename\")?.AsString ?? throw new LiteException(0, $\"Collection $file requires string as 'filename' or a document field 'filename'\");\n            var format = GetOption(options, \"format\", Path.GetExtension(filename)).AsString;","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Engine/SystemCollections/SysFile.cs#L14-L50","documentation":"Thrown by SysFile.Input when the requested file format is not registered. SysFile ($file) only registers 'json' and 'csv' (case-insensitive). The format is derived from an explicit 'format' option or, if absent, the filename extension (with the leading dot stripped). Any other extension/format string hits this.","triggerScenarios":"Querying db.GetCollection(\"$file\") / SELECT * FROM $file('data.xml') or $file('data.xlsx'), or passing { filename:'data.db', format:'db' }; anything whose resolved format is not json or csv.","commonSituations":"Trying to import XML/Excel/Parquet via $file (unsupported); passing a file with no extension and no explicit format option; typos in the format option like 'jSon' is fine but 'json ' (trailing space) or 'JSON5' is not.","solutions":["Convert the source to JSON or CSV first, then use $file('data.json') or $file('data.csv').","Pass an explicit format option that equals json or csv: { filename:'data', format:'csv' }.","For other formats, parse them in application code and insert documents directly."],"exampleFix":"// before\ndb.Execute(\"SELECT * FROM $file('data.xml')\"); // throws\n\n// after\ndb.Execute(\"SELECT * FROM $file('data.json')\");","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> Supported = new(StringComparer.OrdinalIgnoreCase) { \"json\", \"csv\" };\nstring fmt = Path.GetExtension(path)?.TrimStart('.');\nif (!Supported.Contains(fmt)) throw new ArgumentException($\"Unsupported $file format: {fmt}\");\ndb.Execute($\"SELECT * FROM $file('{path}')\");","typeGuard":"static bool IsSupportedFileFormat(string path) {\n    var ext = Path.GetExtension(path)?.TrimStart('.');\n    return ext == \"json\" || ext == \"csv\";\n}","tryCatchPattern":"try { db.Execute($\"SELECT * FROM $file('{path}')\"); }\ncatch (LiteException ex) when (ex.Message.Contains(\"Unknow file format\")) {\n    // convert to json/csv then retry\n}","preventionTips":["Only feed json/csv to $file.","Validate extensions in the import UI before reaching the engine.","Prefer $file over $file_json/$file_csv for routing."],"tags":["system-collections","file-import","format"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}