Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tech]: Perform schema validation when reading from persistent storage #8

Open
pkerschbaum opened this issue Jan 13, 2022 · 0 comments
Labels

Comments

@pkerschbaum
Copy link
Owner

pkerschbaum commented Jan 13, 2022

Current Behavior

The persistent storage is implemented with electron-store. This module just writes the data into a config.json (put somewhere on the users machine). When this data is read, it is currently just typed as StorageState. But if the data of the JSON file does not match the expected shape, the file explorer can crash.
This already happened during development if the shape was changed but config.json contained data with the old shape.

Desired Behavior

When data is read from the persistent storage, validate that data according to a schema resembling StorageState before continuing. Either using https://github.com/colinhacks/zod or https://github.com/sinclairzx81/typebox + https://github.com/ajv-validator/ajv.
If a validation error occurs, continue with a "blank" state (as if the file explorer started for the first time). This means that any stored data on the user's machine is lost. At the moment, only the explorer tabs are persisted, so no meaningful data should be lost. However, in the future there might be some meaningful data stored in the persistent storage (e.g. tags for files&folders).
In general, changes of the shape of StorageState (and thus, effectively, config.json) should be done in a backwards-compatible manner.

Implementation Notes

@pkerschbaum pkerschbaum changed the title [Improvement]: Perform schema validation when reading from persistent storage [Tech]: Perform schema validation when reading from persistent storage Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant