"Error: No data in the file" when core restarts before any subscriptions have been added
Environment
- OS version: Ubuntu 20.04
- Browser version: Chrome 107
- Extension version: webext 0.7 test extension
- Core version: c7011495
- Enabled Filter lists: None
How to reproduce
- Load the MV3 version of the test extension in Chrome
- Reload the test extension
- Check the service worker console for warnings
Observed behavior
There is a warning in the console:
Error: No data in the file
at FilterStorage.loadFromDisk (filterStorage.js:652:1)
at async FilterListener.initialize (filterListener.js:193:1)
at async initializer.js:48:1
at async onInstalled (index.js:69:1) No data in the file
Expected behavior
There are no warnings.
Additional Information
This is the code where the error is thrown. In short, after loading the filter storage from IO
, it throws an error if the file didn't have any subscriptions.
let parser = this.importData(true);
await IO.readFromFile(FilterStorage.sourceFile, parser);
parser(null);
if (this._knownSubscriptions.size == 0) {
// No filter subscriptions in the file, this isn't right.
throw new Error("No data in the file");
}
- This warning also happens whenever the service worker restarts.
- Adding default subscriptions is now something that extension authors should be doing, so it is valid to have an empty file.
- If the file is empty, it appears that Core falls back to backup files. This isn't correct in this context, and could lead to weird behaviour like removed subscriptions being brought back.
Integrator Notes
The filter storage will now consider files without any subscriptions to be valid, and will not fall back to a backup when it encounters such a file. Integrators should ensure that the IO
module they provide does atomic saves (files must either be saved or not saved, but never created empty and then not written to). If file integrity checks are required by the underlying storage medium, this must be provided by the IO
module.