feat: print program logs when transaction send fails (#13213)

This commit is contained in:
Justin Starry 2020-10-29 08:59:16 +08:00 committed by GitHub
parent 413dfb01d5
commit e7b7c15198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -2947,6 +2947,14 @@ export class Connection {
const unsafeRes = await this._rpcRequest('sendTransaction', args);
const res = SendTransactionRpcResult(unsafeRes);
if (res.error) {
if (res.error.data) {
const logs = res.error.data.logs;
if (logs && Array.isArray(logs)) {
const traceIndent = '\n ';
const logTrace = traceIndent + logs.join(traceIndent);
console.error(res.error.message, logTrace);
}
}
throw new Error('failed to send transaction: ' + res.error.message);
}
assert(typeof res.result !== 'undefined');