Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add getter for logs to sendTransactionError #2771

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/library-legacy/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {TransactionSignature} from './transaction';
export class SendTransactionError extends Error {
private signature: TransactionSignature;
private transactionMessage: string;
private logs: string[] | Promise<string[]> | undefined;
private transactionLogs: string[] | Promise<string[]> | undefined;

constructor({
action,
Expand Down Expand Up @@ -44,25 +44,32 @@ export class SendTransactionError extends Error {

this.signature = signature;
this.transactionMessage = transactionMessage;
this.logs = logs ? logs : undefined;
this.transactionLogs = logs ? logs : undefined;
}

get transactionError(): {message: string; logs?: string[]} {
return {
message: this.transactionMessage,
logs: Array.isArray(this.logs) ? this.logs : undefined,
logs: Array.isArray(this.transactionLogs)
? this.transactionLogs
: undefined,
};
}

/* @deprecated Use `await getLogs()` instead */
get logs() {
return this.transactionLogs as string[] | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be true, right? It could be a Promise? I think you have to just return undefined if 'then' in this.transactionLogs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I added that check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully now it will not be a breaking change anymore.

}

async getLogs(connection: Connection): Promise<string[]> {
if (!Array.isArray(this.logs)) {
this.logs = new Promise((resolve, reject) => {
if (!Array.isArray(this.transactionLogs)) {
this.transactionLogs = new Promise((resolve, reject) => {
connection
.getTransaction(this.signature)
.then(tx => {
if (tx && tx.meta && tx.meta.logMessages) {
const logs = tx.meta.logMessages;
this.logs = logs;
this.transactionLogs = logs;
resolve(logs);
} else {
reject(new Error('Log messages not found'));
Expand All @@ -71,7 +78,7 @@ export class SendTransactionError extends Error {
.catch(reject);
});
}
return await this.logs;
return await this.transactionLogs;
}
}

Expand Down