{"record":{"id":"650d5a6dcfa69bd1","repo":"SubtitleEdit/subtitleedit","slug":"nocr-database-is-empty-nocrdbpath","errorCode":null,"errorMessage":"nOCR database is empty: {nOcrDbPath}","messagePattern":"nOCR database is empty: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/NOcrOcrEngine.cs","lineNumber":30,"sourceCode":"{\n    public string Name => \"nocr\";\n    private readonly NOcrDb _db;\n    private readonly NOcrCaseFixer _caseFixer = new();\n    private const int MaxWrongPixels = 25;\n    private const int PixelsAreSpaceDefault = 12;\n\n    public NOcrOcrEngine(string nOcrDbPath)\n    {\n        if (!File.Exists(nOcrDbPath))\n        {\n            throw new FileNotFoundException(\n                $\"nOCR database not found: {nOcrDbPath}. Use --ocr-db to point to a .nocr file \" +\n                \"(typically %AppData%\\\\Subtitle Edit\\\\OCR\\\\Latin.nocr or similar).\", nOcrDbPath);\n        }\n        _db = new NOcrDb(nOcrDbPath);\n        if (_db.TotalCharacterCount == 0)\n        {\n            throw new InvalidOperationException($\"nOCR database is empty: {nOcrDbPath}\");\n        }\n    }\n\n    public string Recognize(SKBitmap bitmap)\n    {\n        if (bitmap is null || bitmap.Width == 0 || bitmap.Height == 0)\n        {\n            return string.Empty;\n        }\n\n        var parent = new NikseBitmap2(bitmap);\n        parent.MakeTwoColor(200);\n        parent.CropTop(0, new SKColor(0, 0, 0, 0));\n        var letters = NikseBitmapImageSplitter2.SplitBitmapToLettersNew(\n            parent, PixelsAreSpaceDefault, rightToLeft: false, topToBottom: true, minLineHeight: 20, autoHeight: true);\n\n        var matches = new List<NOcrChar>();\n        var i = 0;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/NOcrOcrEngine.cs#L12-L48","documentation":"Thrown by NOcrOcrEngine after successfully opening the .nocr file but finding `NOcrDb.TotalCharacterCount == 0`. This means the file exists but contains zero trained character entries, so recognition would return nothing. It guards against a silently broken db being mistaken for an empty subtitle.","triggerScenarios":"Constructing `new NOcrOcrEngine(path)` where the file at `path` parses without throwing but yields no character definitions — e.g. an empty placeholder .nocr, a truncated/corrupt download, or a text file mistakenly renamed to .nocr.","commonSituations":"An interrupted download of Latin.nocr; pointing --ocr-db at a stale or hand-created stub; a .nocr exported from an incompatible SE version whose format changed.","solutions":["Re-download Latin.nocr from the official Subtitle Edit source or copy it from a working SE installation.","Open the .nocr in the Subtitle Edit GUI OCR trainer to confirm it has characters; re-export if empty.","Point --ocr-db at a known-good db file and re-run.","Fall back to tesseract (`--ocr-engine tesseract`) until a valid nOCR db is available."],"exampleFix":"// before\n--ocr-db=./Latin.nocr   // 0-byte / corrupt file\n// after\n--ocr-db=./Latin-good.nocr   // verified non-empty db","handlingStrategy":"try-catch","validationCode":"var db = new NOcrDb(path);\nif (db.TotalCharacterCount == 0)\n    throw new InvalidOperationException(\"nOCR db has no characters: \" + path);","typeGuard":"static bool IsNocrDbPopulated(string path)\n{\n    try { return new NOcrDb(path).TotalCharacterCount > 0; }\n    catch { return false; }\n}","tryCatchPattern":"try { var engine = new NOcrOcrEngine(path); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"nOCR database is empty\"))\n{\n    // flag corrupt db, skip file, continue batch\n}","preventionTips":["Validate TotalCharacterCount > 0 after opening the db in your bootstrap.","Checksum known-good .nocr files in CI so a corrupt copy is caught early.","Keep a golden copy of Latin.nocr and diff against it on deployment."],"tags":["ocr","nocr","data-validation","corrupt-file"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}