Backport add error handling to the file cache upgrade

And the backport to stable5.

@icewind1991 @Raydiation