-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[TS SDK] Return txn data on success and txn failure reason on failure #9433
Conversation
@@ -672,7 +672,7 @@ export class AptosClient { | |||
} | |||
if (!(lastTxn as any)?.success) { | |||
throw new FailedTransactionError( | |||
`Transaction ${txnHash} committed to the blockchain but execution failed`, | |||
`Transaction ${txnHash} failed with an error: ${(lastTxn as any).vm_status}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay :D Is there any way we can put the vm_status
in a field in the FailedTransactionError
class? I actually don't know if this makes sense, but it would make it easier to use instead of parsing it. Is it generally not a good idea to add fields to existing classes if the sdk exposes them with export, or would it not really matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have the full txn object part of the FailedTransactionError
class. but as mentioned in the PR comment, Error class is a bit weird as it only outputs the "message" prop, unless we wrap it with try/catch and then we can get access to the other class properties, it feels like a big change for this use case and that should be good for now.
We can always just return the full transaction object, but then we lost the "message" part, i.e you won't see Transaction ${txnHash} failed with an error: ${(lastTxn as any).vm_status}
but only a txn object and then you would need to look for the success
prop to see if it succeed or failed - basically same response for a success txn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh duh, I forgot the txn object is in the error! Yeah this is great, I think it makes most sense this way then
5e3aa1d
to
7dffa25
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
The sdk provides a way to return the txn data when it succeed, added an example/test on how to use it.
For when a txn has failed, we throw an error with the txn hash and the failure reason message - Error class is a bit weird as it only outputs the "message" prop, unless we wrap it with try/catch and then we can get access to the other class properties, it feels like a big change for this use case and that should be good for now.
Test Plan