本地存储错误 - NS_ERROR_FILE_CORRUPTED - firefox [英] Error in local storage - NS_ERROR_FILE_CORRUPTED - firefox

查看:446
本文介绍了本地存储错误 - NS_ERROR_FILE_CORRUPTED - firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在一个Web应用程序工作,我正在使用本地存储。但对于一些Firefox用户,我注意到他们有以下错误:


NS_ERROR_FILE_CORRUPTED:组件返回失败代码:0x8052000b
(NS_ERROR_FILE_CORRUPTED)[nsIDOMStorage.setItem]


当它调用函数时:

 函数setLocalStorageItem(key,value){
localStorage.setItem(key,JSON.stringify(value));
}

这是避免这种错误的方法吗?这是一个浏览器级别的错误:你可能没有做任何错误导致这个错误。浏览器(或者它使用的SQLite库)要么做错了,要么由于硬件问题导致文件处于无效状态。



你不能除了加入Firefox开发团队并使浏览器的存储系统更具有防故障性之外,真正阻止了这个问题。似乎没有办法从这个错误中恢复数据,所以你需要做的就是检测这个错误,并告诉用户如何根据 rel =noreferrer a>:

  try {
setLocalStorageItem(key,value);
} catch(e){
if(e.name ==NS_ERROR_FILE_CORRUPTED){
showMessageSomehow(抱歉,您的浏览器存储空间已损坏,请清空存储空间去工具 - >清除最近的历史记录>饼干和时间范围设置为一切,这将删除所有网站上损坏的浏览器存储。




$ p $注意 catch 块应该验证错误是 NS_ERROR_FILE_CORRUPTED 错误。我想我对 e.name 的检查是正确的,但你应该自己核实。


I've been working in a web application and I'm using local storage. But for some Firefox users I notice that they're having the following error:

NS_ERROR_FILE_CORRUPTED: Component returned failure code: 0x8052000b (NS_ERROR_FILE_CORRUPTED) [nsIDOMStorage.setItem]

when it called the function:

function setLocalStorageItem(key, value){ 
        localStorage.setItem(key, JSON.stringify(value));
}

It's is a way to avoid this error?

解决方案

This is a browser-level error: you probably didn't do anything wrong to cause this error. The browser (or the the SQLite library it uses) either did something wrong, or the file was left in an invalid state due to a hardware problem.

You can't really prevent this issue, except by joining the Firefox development team and making the browser's storage system more fault-resistant. There doesn't seem to be any way to restore data from this error, so what you'll have to do is detect this error and tell users how to blow away their browser storage according to this MDN post:

try {
    setLocalStorageItem(key, value);
} catch(e) {
    if(e.name == "NS_ERROR_FILE_CORRUPTED") {
        showMessageSomehow("Sorry, it looks like your browser storage has been corrupted. Please clear your storage by going to Tools -> Clear Recent History -> Cookies and set time range to 'Everything'. This will remove the corrupted browser storage across all sites.");
    }
}

Note that the catch block should verify that the error is an NS_ERROR_FILE_CORRUPTED error. I think my check on e.name is correct, but you should verify it for yourself.

这篇关于本地存储错误 - NS_ERROR_FILE_CORRUPTED - firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆