Repository navigation
LT-21638: Stop SFM import crashing on a blank Database File - #1231
Conversation
In File > Import > Standard Format Lexicon, clicking Save, or answering Yes to the Save settings? question on Cancel, crashed with "The path is not of a legal form" when the Database File box was blank or named a file that does not exist. Saving fills in every wizard step first, and the marker step reads the input file's timestamp. The wizard's file-name check now rejects a blank or missing Database File before anything else. Save, Finish and Quick Finish warn and stay put; Cancel closes without offering to save, as it already did for an empty box. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1231 +/- ##
=======================================
Coverage 40.51% 40.51%
=======================================
Files 1559 1559
Lines 356080 356091 +11
Branches 41585 41589 +4
=======================================
+ Hits 144262 144288 +26
+ Misses 182505 182491 -14
+ Partials 29313 29312 -1
🚀 New features to boost your workflow:
|
A Database File named PhaseNOutput.xml that does not exist showed the new missing-file warning, and then Next still jumped to the import step. The jump to the import step now runs only when the file check passes, and Next stays disabled on the file step until the database file exists, phase output files included. The UsesInvalidFileNames summary now states only its own contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jasonleenaylor
left a comment
There was a problem hiding this comment.
Clean fix. One question on the tests.
| public void UsesInvalidFileNames_BlankDatabaseFile_IsInvalid(string databaseFile) | ||
| { | ||
| var settingsFile = CreateFile("import-settings.map"); | ||
| using (var wizard = new LexImportWizard()) |
There was a problem hiding this comment.
We'd like to avoid constructing WinForms forms in unit tests. new LexImportWizard() runs the designer's InitializeComponent(), and these tests depend on its TextChanged handlers staying inert before the form loads. Could these three tests either test a no-WinForms helper, like you did with CanLeaveFileStep, or be dropped? The database-file check is a single File.Exists, so they may not be testing anything of value.
There was a problem hiding this comment.
Thanks! Those tests have been removed.
The UsesInvalidFileNames tests constructed LexImportWizard and so ran the designer code, relying on its text-changed handlers doing nothing before the form loads. The rule they checked, that a blank or missing database file is unusable, is covered by the CanLeaveFileStep tests, which need no form. UsesInvalidFileNames is private again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| public void UsesInvalidFileNames_BlankDatabaseFile_IsInvalid(string databaseFile) | ||
| { | ||
| var settingsFile = CreateFile("import-settings.map"); | ||
| using (var wizard = new LexImportWizard()) |
There was a problem hiding this comment.
Thanks! Those tests have been removed.
Clicking Save in the Standard Format lexicon import wizard, or answering Yes to "Save settings?" after Cancel, no longer crashes when the Database File box is blank or names a file that does not exist. The wizard says what is wrong and stays on the page: "The database file must be defined." for a blank box, or "The selected database file (...) does not exist." for a missing one. Finish and Quick Finish give the same warnings, and Cancel closes without offering to save.
Next on the first page also stays disabled until the database file exists. Until now a missing file whose name ended in
PhaseNOutput.xmllet Next jump straight to the import step, which then failed.Reviewer notes
Root cause. Saving settings first runs every wizard step to fill in its data, and the marker step calls
File.GetLastWriteTimeon the Database File path, which throws "The path is not of a legal form" for a blank path. The 2023 fix (43507dc) skipped the save prompt on Cancel only when the box was completely empty, so QA's later repro on the ticket (choose a file, clear the box, click Save) went around it.Deliberate rules.
UsesInvalidFileNamesrejects a blank or missing database file before checking anything else. It already runs before Save, Finish, Quick Finish, Next (step 2) and Cancel, so one guard covers every way into the step rebuild, and the separate empty-string test on Cancel is folded into it. Returning early also skipsSetDefaultSettings, which derives the save-as name from the database path.OnNextButtonthe phase-file jump to the import step is anelse ifafter that check, so a warning is never followed by navigation.CanLeaveFileStepdecides when Next is enabled on the first page: the database file must exist, phase output files included. Other files are judged as before, including the rule against saving over the shippedMDFImport.map. It is static so tests can call it without a form.ksUndefinedDatabaseFileandksInvalidDatabaseFileX, follow the wording of the existing settings-file messages. No existing resource key changed meaning.Tests. New
LexImportWizardTestscoverCanLeaveFileStepwith missing and existing phase files, blank and whitespace-only paths, saving over the shipped map, and a valid file; none of them constructs the wizard form. The missing-phase-file case fails against the old code.UsesInvalidFileNamesand the Save, Cancel and Next handlers are not unit-tested, because exercising them means building the form, and the handlers open modal message boxes. LexTextControlsTests: 413 passed, 3 skipped; the build and comment and token hygiene are clean.Manual tests (not done). The acceptance steps on LT-21638 have not been run in FLEx; QA covers them on the nightly build.
Out of scope. The wizard has no Avalonia counterpart, so there is nothing to keep in step.
🤖 Generated with Claude Code
This change is