Better bad transaction error and auto reset database from unrecoverable state #2031
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #1847 (comment)
If the database gets into a state where there are no object stores, there is also no data present and it is safe to delete the database to recover. It may not be safe to delete the database in other situations, so the user will be presented with a more descriptive error instead if it hits a transaction failure.
Transaction failures seem to be almost always caused by a missing object store and would be an unrecoverable state even if only a single one is missing but there is no evidence of such cases occurring and I currently do not like the idea of potentially bulldozing user data for recovery. In a database corruption with missing object stores it is still technically possible for the user to manually extract some amount of data even if only one object store is present.
It is not possible to repair the database on Yomitan's end after losing some or all of the object stores without pushing a version change which are meant to be for schema updates and it is probably not a good idea to throw them around arbitrarily as it could cause the database to be unopenable or impossible to update in the future if the version number is something unexpected.
https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/createObjectStore
To intentionally create a broken database with missing object stores, throw an error right after opening the database here:
yomitan/ext/js/data/database.js
Line 332 in 605f70f
For example: