What's wrong
SchemaFile.TrySave (Schema.Editor/SchemaFile.cs, the try around Directory.CreateDirectory / File.WriteAllText) catches only JsonException and IOException. Both of those calls throw UnauthorizedAccessException when the target file is read-only or the directory isn't writable, and UnauthorizedAccessException is not an IOException, so it escapes.
SchemaFile.Load in the same file already catches UnauthorizedAccessException, so the load and save paths handle the same failure differently.
There is nothing above the save path to catch it. SaveToCurrentPath (Schema.Editor/SchemaEditor.Files.cs) expects TrySave to return false and then shows the "Failed to save schema to '...'" popup. That popup is never reached.
Failure scenario
- Open a
.schema.json that is read-only, for example a Perforce or other VCS checkout that isn't opened for edit, or a file with attrib +r. Alternatively, use Save As into a directory you can't write to.
- Make edits.
- Press Ctrl+S, choose File > Save, or click "Save" on the unsaved-changes prompt that appears when you close the editor.
UnauthorizedAccessException escapes the ImGui frame callback and the editor terminates. The edits the user was trying to save are lost.
Secondary problem in the same flow
SaveAs assigns CurrentSchemaPath = filePath before it attempts the save. Even once the crash is fixed, a Save As that fails leaves the document pointing at the path that failed. The window title shows that path, and the next Ctrl+S writes there instead of to the previous good path.
Suggested fix
Related but distinct: #243 covers the same exception class in GenerateToDisk / kschema, not the editor's document save.
What's wrong
SchemaFile.TrySave(Schema.Editor/SchemaFile.cs, thetryaroundDirectory.CreateDirectory/File.WriteAllText) catches onlyJsonExceptionandIOException. Both of those calls throwUnauthorizedAccessExceptionwhen the target file is read-only or the directory isn't writable, andUnauthorizedAccessExceptionis not anIOException, so it escapes.SchemaFile.Loadin the same file already catchesUnauthorizedAccessException, so the load and save paths handle the same failure differently.There is nothing above the save path to catch it.
SaveToCurrentPath(Schema.Editor/SchemaEditor.Files.cs) expectsTrySaveto returnfalseand then shows the"Failed to save schema to '...'"popup. That popup is never reached.Failure scenario
.schema.jsonthat is read-only, for example a Perforce or other VCS checkout that isn't opened for edit, or a file withattrib +r. Alternatively, use Save As into a directory you can't write to.UnauthorizedAccessExceptionescapes the ImGui frame callback and the editor terminates. The edits the user was trying to save are lost.Secondary problem in the same flow
SaveAsassignsCurrentSchemaPath = filePathbefore it attempts the save. Even once the crash is fixed, a Save As that fails leaves the document pointing at the path that failed. The window title shows that path, and the next Ctrl+S writes there instead of to the previous good path.Suggested fix
UnauthorizedAccessExceptioninTrySave. Ideally, return the failure reason the wayLoaddoes (Message = ...), so the popup can say why the save failed (read-only, access denied) instead of giving a generic message.SaveAs, assignCurrentSchemaPathonly after the save succeeds, or restore the previous path when it fails.SchemaFileTestscase that saves over a read-only file and asserts thatTrySavereturnsfalseinstead of throwing.Related but distinct: #243 covers the same exception class in
GenerateToDisk/ kschema, not the editor's document save.