优化错误处理
parent
c663cdbe0d
commit
5ed81132fb
|
@ -12,24 +12,30 @@ const stores = {}
|
||||||
* @param {*} isIgnoredError 是否忽略错误
|
* @param {*} isIgnoredError 是否忽略错误
|
||||||
* @returns Store
|
* @returns Store
|
||||||
*/
|
*/
|
||||||
module.exports = (name, isIgnoredError = true) => {
|
module.exports = (name, isIgnoredError = true, isShowErrorAlert = true) => {
|
||||||
if (stores[name]) return stores[name]
|
if (stores[name]) return stores[name]
|
||||||
let store
|
let store
|
||||||
try {
|
try {
|
||||||
store = stores[name] = new Store({ name, clearInvalidConfig: false })
|
store = stores[name] = new Store({ name, clearInvalidConfig: false })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(error)
|
log.error(error)
|
||||||
|
|
||||||
if (!isIgnoredError) throw error
|
if (!isIgnoredError) throw error
|
||||||
|
|
||||||
|
|
||||||
const backPath = path.join(app.getPath('userData'), name + '.json.bak')
|
const backPath = path.join(app.getPath('userData'), name + '.json.bak')
|
||||||
fs.copyFileSync(path.join(app.getPath('userData'), name + '.json'), backPath)
|
fs.copyFileSync(path.join(app.getPath('userData'), name + '.json'), backPath)
|
||||||
dialog.showMessageBoxSync({
|
|
||||||
type: 'error',
|
|
||||||
message: name + ' data load error',
|
|
||||||
detail: `We have helped you back up the old ${name} file to: ${backPath}\nYou can try to repair and restore it manually\n\nError detail: ${error.message}`,
|
|
||||||
})
|
|
||||||
store = new Store({ name, clearInvalidConfig: true })
|
|
||||||
shell.showItemInFolder(backPath)
|
shell.showItemInFolder(backPath)
|
||||||
|
if (isShowErrorAlert) {
|
||||||
|
dialog.showMessageBoxSync({
|
||||||
|
type: 'error',
|
||||||
|
message: name + ' data load error',
|
||||||
|
detail: `We have helped you back up the old ${name} file to: ${backPath}\nYou can try to repair and restore it manually\n\nError detail: ${error.message}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
store = new Store({ name, clearInvalidConfig: true })
|
||||||
}
|
}
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ const getStore = require('@common/store')
|
||||||
|
|
||||||
|
|
||||||
mainHandle(ipcMainWindowNames.get_playlist, async(event, isIgnoredError = false) => {
|
mainHandle(ipcMainWindowNames.get_playlist, async(event, isIgnoredError = false) => {
|
||||||
const electronStore_list = getStore('playList', isIgnoredError)
|
const electronStore_list = getStore('playList', isIgnoredError, false)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaultList: electronStore_list.get('defaultList'),
|
defaultList: electronStore_list.get('defaultList'),
|
||||||
|
|
Loading…
Reference in New Issue