Skip to content

Commit 90ff5a8

Browse files
committed
优化:错误细化显示
1 parent ac9e8f1 commit 90ff5a8

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

electron/mapi/manager/plugin/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export const ManagerPlugin = {
386386
async refreshInstall(name: string) {
387387
const doc = await KVDBMain.get(CommonConfig.dbSystem, `${CommonConfig.dbPluginIdPrefix}/${name}`)
388388
if (!doc) {
389-
throw `PluginNotFound : ${name}`
389+
throw `PluginNotExists : ${name}`
390390
}
391391
const pluginInfo: PluginInfo = doc as any
392392
const root = pluginInfo.root
@@ -419,15 +419,15 @@ export const ManagerPlugin = {
419419
async uninstall(name: string) {
420420
const plugin = await this.get(name)
421421
if (!plugin) {
422-
throw `PluginNotFound : ${name}`
422+
throw `PluginNotExists:-1:${name}`
423423
}
424424
const pi = await KVDBMain.get(CommonConfig.dbSystem, `${CommonConfig.dbPluginIdPrefix}/${name}`)
425425
if (!pi) {
426-
throw `PluginNotFound : ${name}`
426+
throw `PluginNotExists:-2:${name}`
427427
}
428428
const info: PluginInfo = pi as any
429429
if (!info.name || !info.version || !info.type || !info.config) {
430-
throw `PluginNotFound : ${name}`
430+
throw `PluginNotExists:-3:${name}`
431431
}
432432
await ManagerBackend.run(plugin, 'hook', 'beforeUninstall', {})
433433
if (info.type === PluginType.STORE || info.type === PluginType.ZIP) {

electron/mapi/manager/system/plugin/store/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export const ManagerPluginStore = {
100100
if (!configJson) {
101101
throw 'PluginFormatError:-10'
102102
}
103+
if (configJson['name'] !== pluginName) {
104+
throw 'PluginFormatError:-11'
105+
}
103106
const payload = {
104107
plugin: pluginName,
105108
version: option['version'],
@@ -197,15 +200,15 @@ export const ManagerPluginStore = {
197200
isFullPath: true,
198201
})
199202
if (!config) {
200-
throw 'PluginFormatError:-11'
203+
throw 'PluginFormatError:-12'
201204
}
202205
let configJson = null
203206
try {
204207
configJson = JSON.parse(config)
205208
} catch (e) {
206209
}
207210
if (!configJson) {
208-
throw 'PluginFormatError:-12'
211+
throw 'PluginFormatError:-13'
209212
}
210213
const payload = {
211214
plugin: pluginName,

src/lib/error.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ export function mapError(msg: any) {
1616
if (msg.includes(key)) {
1717
let error = map[key]
1818
// regex PluginReleaseDocFormatError:-11
19-
const regex = new RegExp(`${key}:(-?\\d+)`)
19+
const regex = new RegExp(`${key}:(-?\\d+):?([\\w\\d]*)`)
2020
const match = msg.match(regex)
21+
console.log('match', match)
2122
if (match) {
2223
error += `(${match[1]})`
24+
if (match[2]) {
25+
error += `(${match[2]})`
26+
}
2327
}
2428
return error
2529
}

0 commit comments

Comments
 (0)