{"record":{"id":"2d340b2d6d117dfd","repo":"tui-cs/Terminal.Gui","slug":"filepath","errorCode":null,"errorMessage":"FilePath","messagePattern":"FilePath","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/TextInput/TextModel.cs","lineNumber":83,"sourceCode":"        }\n\n        return false;\n    }\n\n    /// <summary>Adds a line to the model at the specified position.</summary>\n    /// <param name=\"pos\">Line number where the line will be inserted.</param>\n    /// <param name=\"cells\">The line of text and color, as a List of Cell.</param>\n    public void AddLine (int pos, List<Cell> cells)\n    {\n        _lines.Insert (pos, cells);\n        InvalidateMaxWidthCache ();\n    }\n\n    public bool CloseFile ()\n    {\n        if (FilePath is null)\n        {\n            throw new ArgumentNullException (nameof (FilePath));\n        }\n\n        FilePath = null;\n        _lines = [];\n        InvalidateMaxWidthCache ();\n\n        return true;\n    }\n\n    public List<List<Cell>> GetAllLines () => _lines;\n\n    /// <summary>Returns the specified line as a List of Rune</summary>\n    /// <returns>The line.</returns>\n    /// <param name=\"line\">Line number to retrieve.</param>\n    public List<Cell> GetLine (int line)\n    {\n        if (_lines.Count > 0)\n        {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/TextInput/TextModel.cs#L65-L101","documentation":"Thrown by TextModel.CloseFile (ArgumentNullException, param 'FilePath') when FilePath is null. CloseFile expects an open file to close and uses FilePath as the subject; a null FilePath means no file was ever loaded, so closing is meaningless. After throwing it never clears state, so the model is unchanged.","triggerScenarios":"Calling CloseFile() on a TextModel that never had LoadFile/LoadStream setting FilePath, or after FilePath was already nulled by a previous successful CloseFile. Essentially 'close without prior open'.","commonSituations":"Editor wiring that calls CloseFile on shutdown regardless of whether a file was opened; reusing a TextModel across documents and closing when none is bound; a 'new document' path that never sets FilePath then invokes close.","solutions":["Guard the call: if (textModel.FilePath is not null) textModel.CloseFile();","Track open-file state separately and only close when a file is actually open.","Reuse the same null-check the method itself enforces, but at the call site for a cleaner user experience."],"exampleFix":"// before\ntextModel.CloseFile(); // FilePath null -> throws 175\n\n// after\nif (textModel.FilePath is not null)\n{\n    textModel.CloseFile();\n}","handlingStrategy":"validation","validationCode":"if (textModel.FilePath is not null)\n{\n    textModel.CloseFile();\n}","typeGuard":"static bool HasOpenFile(TextModel m) => m.FilePath is not null;","tryCatchPattern":null,"preventionTips":["Guard CloseFile with a FilePath null-check.","Track open-file state separately for shutdown logic.","Do not close a model that was never opened."],"tags":["textmodel","file","nullable","precondition"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}