Skip to content

Commit

Permalink
🐛 Fix(error): throw error when transform failed (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
upupming authored Aug 21, 2021
1 parent d2b73c1 commit 57fce75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/core/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/PicGo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down
20 changes: 8 additions & 12 deletions src/plugins/transformer/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@ const handle = async (ctx: IPicGo): Promise<IPicGo> => {
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
Expand Down

0 comments on commit 57fce75

Please sign in to comment.