handle exception in dtm
This commit is contained in:
parent
3f040b2c2c
commit
e3a94d1f76
@ -29,11 +29,18 @@ class DtmWrapper {
|
|||||||
});
|
});
|
||||||
|
|
||||||
child.on('close', (code) => {
|
child.on('close', (code) => {
|
||||||
if (code === 0) {
|
try {
|
||||||
resolve(JSON.parse(stdout.trim()));
|
const parsedOutput = JSON.parse(stdout.trim());
|
||||||
} else {
|
if (code === 0) {
|
||||||
reject(JSON.parse(stdout.trim()));
|
resolve(parsedOutput);
|
||||||
}
|
} else {
|
||||||
|
reject(parsedOutput);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 处理 JSON 解析异常
|
||||||
|
const errorObj = error as Error;
|
||||||
|
reject({ status: -1, message: 'JSON parse error', log: errorObj.message });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -50,10 +57,10 @@ class DtmWrapper {
|
|||||||
try {
|
try {
|
||||||
return await this.runCommand('dtm', ['commit', '-m', commitMsg, '-o', 'json']);
|
return await this.runCommand('dtm', ['commit', '-m', commitMsg, '-o', 'json']);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 处理异常
|
// 处理 runCommand 中的 reject 错误
|
||||||
console.error('Error in commit:', error);
|
console.error('Error in commit:', error);
|
||||||
return {'status': -1, 'message': 'exception error', 'log': 'exception error'};
|
return error as DtmResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user