Skip to content

fix(prefs): skip saved preferences the class does not declare - #172

Merged
ehennestad merged 2 commits into
devfrom
skip-unknown-saved-preferences
Nov 5, 2026
Merged

ehennestad merged 2 commits into
devfrom
skip-unknown-saved-preferences

Conversation

@ehennestad

Copy link
Copy Markdown
Collaborator

nansen.config.abstract.Preferences loads its preference file in the constructor, and fromStruct assigned every field of the saved struct onto the object. The file is written by toStruct, which saves the public properties of whichever version of the subclass is running. A file written by a version with a renamed or removed preference therefore holds a field the running class does not declare, and the assignment errors with "Unrecognized property". NansenUserSession constructs nansen.internal.user.Preferences at startup, so every entry point to NANSEN fails before anything is shown.

This happens today when switching between dev and the branch of #126. That branch renames UserdataDirectory to UserDataDirectory, and one run of it rewrites NansenUserSession_Preferences.mat with the new name. Going back to dev then fails on startup until the file is edited by hand.

fromStruct now assigns only the saved names that the class declares. A skipped value is dropped by the next save, which writes the declared preferences only. #126 carries the same hardening in its own version of this method, so merging dev into that branch will conflict on this block. Keeping dev's version resolves it.

nansen.unittest.config.PreferencesTest writes a preference file for a throwaway profile and starts a user session for it, once with declared preferences only and once with an extra unknown field.

The second commit corrects the H1 line of getActivePreferenceGroup, which named a different method.

🤖 Generated with Claude Code

ehennestad and others added 2 commits November 5, 2026 14:42
nansen.config.abstract.Preferences/fromStruct assigned every field of
the saved struct onto the object. A preference file written by another
version of NANSEN, with a renamed or removed preference, therefore made
the constructor error, and NansenUserSession constructs the preferences
at startup, so every entry point failed with "Unrecognized property".

The loader now assigns only the saved names the class declares. The
test writes a preference file with an unknown field for a throwaway
profile and starts a session for it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ehennestad
ehennestad merged commit bba56dc into dev Nov 5, 2026
2 checks passed
ehennestad added a commit that referenced this pull request Nov 6, 2026
Conflicts:
- .github/badges/tests.svg: dev's version.
- Preferences.m: dev's fromStruct (#172). It skips saved preferences
  the class does not declare, as this branch's version did.

NansenUserSession.m merges without a conflict, but the merge puts
getUserDataDirectory and getDefaultUserDataDirectory after #127's
confirmNewUserProfile, inside its methods (Static, Access = private)
block. They are moved back to the public static block, because
nansen.userdatadir, clear_tutorial_data, ProjectFixture and
UserDataDirectoryTest call them from outside the class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant