From b63eabf6727867ab2baf464b1242ce03fb1c2b27 Mon Sep 17 00:00:00 2001 From: Yiming Li Date: Sat, 21 Aug 2021 13:01:40 +0800 Subject: [PATCH] :bug: Fix(error): throw error when transform failed --- src/core/Lifecycle.ts | 2 +- src/core/PicGo.ts | 2 +- src/plugins/transformer/path.ts | 20 ++++++++------------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/core/Lifecycle.ts b/src/core/Lifecycle.ts index 60ce85b..9df9a2d 100644 --- a/src/core/Lifecycle.ts +++ b/src/core/Lifecycle.ts @@ -31,7 +31,7 @@ class Lifecycle extends EventEmitter { await this.afterUpload(ctx) return ctx } catch (e) { - ctx.log.warn('failed') + ctx.log.warn(IBuildInEvent.FAILED) ctx.emit(IBuildInEvent.UPLOAD_PROGRESS, -1) ctx.emit(IBuildInEvent.FAILED, e) ctx.log.error(e) diff --git a/src/core/PicGo.ts b/src/core/PicGo.ts index 9578eee..96b9b38 100644 --- a/src/core/PicGo.ts +++ b/src/core/PicGo.ts @@ -186,7 +186,7 @@ class PicGo extends EventEmitter implements IPicGo { if (imgPath === 'no image') { throw new Error('image not found in clipboard') } else { - this.once('failed', () => { + this.once(IBuildInEvent.FAILED, () => { if (!isExistFile) { // 删除 picgo 生成的图片文件,例如 `~/.picgo/20200621205720.png` fs.remove(imgPath).catch((e) => { this.log.error(e) }) diff --git a/src/plugins/transformer/path.ts b/src/plugins/transformer/path.ts index b0d1370..470ebac 100644 --- a/src/plugins/transformer/path.ts +++ b/src/plugins/transformer/path.ts @@ -16,20 +16,16 @@ const handle = async (ctx: IPicGo): Promise => { info = await getFSFile(item) } if (info.success && info.buffer) { - try { - const imgSize = getImgSize(ctx, info.buffer, item) - results[index] = { - buffer: info.buffer, - fileName: info.fileName, - width: imgSize.width, - height: imgSize.height, - extname: info.extname - } - } catch (e) { - ctx.log.error(e) + const imgSize = getImgSize(ctx, info.buffer, item) + results[index] = { + buffer: info.buffer, + fileName: info.fileName, + width: imgSize.width, + height: imgSize.height, + extname: info.extname } } else { - ctx.log.error(info.reason) + throw new Error(info.reason) } })) // remove empty item