Handle zero byte registry.json file #2435
Merged
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.
Problem
If your
registry.json
file is zero bytes long, CKAN crashes on load:Cause
RegistryManager
approaches registry creation by trying to loadregistry.json
and then creating a new file if an exception is thrown during the load attempt. If the file contains a valid registry, it is simply loaded. If it doesn't exist, then a missing file exception is caught and the file is created.If the file exists but is empty, then no exceptions are thrown, but the registry reference is set to null. Later, we attempt to use this reference, which causes an exception that isn't caught.
I was not able to figure out a way that a zero-byte file could be created. It might have something to do with the
ChinhDo.Transactions
library that CKAN uses for some filesystem access; I looked into this library at one point, and it essentially creates a temp folder and then copies files in/out of it, so maybe weird things can happen with files if something goes wrong with that.Changes
Now if the attempt to load returns a null reference, we fall back to
Registry.Empty()
. This allows the load attempt to complete without errors, and the application will work as normal.A test is added to check that loading an empty registry file generates an empty registry without exceptions.
Fixes #2433.