Skip to content

feat: add generic msg on failed transactions in toasts - #587

Merged
metalboyrick merged 2 commits into
Scaffold-Stark:developfrom
Jonatan-Chaverri:better_error_msg_handling
Jul 9, 2025
Merged

feat: add generic msg on failed transactions in toasts#587
metalboyrick merged 2 commits into
Scaffold-Stark:developfrom
Jonatan-Chaverri:better_error_msg_handling

Conversation

@Jonatan-Chaverri

Copy link
Copy Markdown
Contributor

Task name here

Fixes #573

Types of change

  • Feature
  • Bug
  • Enhancement

Comments (optional)

@metalboyrick
metalboyrick changed the base branch from main to develop July 1, 2025 03:36

@metalboyrick metalboyrick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

GM @Jonatan-Chaverri , thanks for your PR! You got the idea right. Leaving some comments and thoughts for improvement

  1. Can we improve the style? (fix the padding and margins)

image

  1. Can we have a clickable link that points us to the specific log from the toast? so that it is easier to trace the error logs for other developers

  2. Can we extract some common errors like insufficient balance or approval required? We can discuss this further if you think this is possible / not possible

@metalboyrick

Copy link
Copy Markdown
Collaborator

GM @Jonatan-Chaverri, any updates on this?

@Jonatan-Chaverri

Copy link
Copy Markdown
Contributor Author

@metalboyrick I will work on this today and provide an update at the EOD

@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch from c187bc3 to b7e8824 Compare July 2, 2025 20:27
@Jonatan-Chaverri

Copy link
Copy Markdown
Contributor Author

@metalboyrick I have addressed the first two requests.

For the third, we can have a file similar to this
https://github.com/starknet-io/types-js/blob/main/src/api/errors.ts#L107

and translate each code to a more verbose error message, is that what you mean? if not, please elaborate a little more. Thanks.

@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch 2 times, most recently from 4a36e4e to 82646cc Compare July 2, 2025 21:29
@metalboyrick

Copy link
Copy Markdown
Collaborator

@Jonatan-Chaverri Yeah something like that would be great, because it gives better clarity to users rather than some strange JSON. You can try out some common ones like insufficient balance, no approval. (be mindful of which errors are common which errors can be user-specific)

@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch 2 times, most recently from 1bf9c79 to d85efc2 Compare July 4, 2025 00:14
@Jonatan-Chaverri

Copy link
Copy Markdown
Contributor Author

@metalboyrick I updated the PR, let me know your thoughts, thanks.

@metalboyrick metalboyrick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix!

Can fix the styling ser, please make sure the margins and paddings are not too wide, we do not need the dark background as well.

image

Also, I did not see the common error po up when transferring insufficient balance

image

@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch from d85efc2 to 4b28de7 Compare July 4, 2025 20:53
@Jonatan-Chaverri

Copy link
Copy Markdown
Contributor Author

@metalboyrick ok, made some changes to fix the margins, this is how it looks now
Screenshot 2025-07-04 at 2 50 45 PM

Also, I tried getting insufficient balance error to test too and this is the error content my function is getting
Screenshot 2025-07-04 at 2 48 22 PM

TypeError: Failed to fetch does not match any known common error so that's why it is not showing in the toast.

I'm not aware of how all starknet common errors are printed, so the file I created is based on assumptions that at least keywords will appear in the error, but again is not 100% reliable until we can confirm that (or if you know how to confirm error messages, you can point me to it and I will update)

@metalboyrick

Copy link
Copy Markdown
Collaborator

@Jonatan-Chaverri for the margins, refer to how the transaction success modal looks, use that as the reference, i think u have a bit too much padding there (this should be easy fix)

As for the errors, you can trial-and-error on what these common errors produce as text, and we can use these keywords are reference for now (not a nice solution but we can make do with this for now), ideally we can decode the bytes somehow

thoughts? @gianalarcon @Nadai2010 @0xquantum3labs @jrcarlos2000 if you have any tips to give?

@metalboyrick
metalboyrick requested a review from gianalarcon July 5, 2025 15:08
@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch from 4b28de7 to 9de9925 Compare July 5, 2025 20:06
@Jonatan-Chaverri

Jonatan-Chaverri commented Jul 5, 2025

Copy link
Copy Markdown
Contributor Author

@metalboyrick ok, I updated the modal. Success modal is just rendering some content (string, or at least that's what I saw in most places) while I'm trying to render a custom reactNode content, so I can't just use the same, but I removed all padding now, so this is how it looks like.
Screenshot 2025-07-05 at 1 42 26 PM

Regarding the error messages I'm not sure how to replicate them all from the tool, that's out of my expertise. Sorry. But will wait to hear if someone has other tips.

@gianalarcon

Copy link
Copy Markdown
Collaborator

@Jonatan-Chaverri for the margins, refer to how the transaction success modal looks, use that as the reference, i think u have a bit too much padding there (this should be easy fix)

As for the errors, you can trial-and-error on what these common errors produce as text, and we can use these keywords are reference for now (not a nice solution but we can make do with this for now), ideally we can decode the bytes somehow

thoughts? @gianalarcon @Nadai2010 @0xquantum3labs @jrcarlos2000 if you have any tips to give?

After a contract is deployed, and we start interacting with this contract, some errors might arises, since these errors comes from starknet nodes, most of the time it just returns a big text with a lot of information(as showed on the issue description ), and usually the most important info is located at the end of this big text, and most of the errors are kind

@gianalarcon gianalarcon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution @Jonatan-Chaverri. I left a comment

Comment thread packages/nextjs/utils/scaffold-stark/errors.tsx Outdated
@Jonatan-Chaverri

Copy link
Copy Markdown
Contributor Author

Could you at least point out the exact errors you mean by "common errors" so I can try to reproduce them?

@gianalarcon

Copy link
Copy Markdown
Collaborator

Could you at least point out the exact errors you mean by "common errors" so I can try to reproduce them?

Yes, totally agree, we should provide more context on the issue description so you can easily reproduce the errors. I think our team to work on this first. WDYT @metalboyrick ?

@metalboyrick

Copy link
Copy Markdown
Collaborator

Gm ser @Jonatan-Chaverri , I think for now we can keep the first half of the PR (the transaction message). Can we remove all logics on the verbose error part but still keep the console notifications part?

@metalboyrick

Copy link
Copy Markdown
Collaborator

I will merge this after that is done

@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch from 9de9925 to 654e0b7 Compare July 8, 2025 21:14
@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch from 654e0b7 to a14c40e Compare July 8, 2025 21:14
@Jonatan-Chaverri
Jonatan-Chaverri force-pushed the better_error_msg_handling branch from a14c40e to b15f396 Compare July 8, 2025 21:15
@Jonatan-Chaverri

Copy link
Copy Markdown
Contributor Author

GM, all done, please check @metalboyrick

@metalboyrick
metalboyrick self-requested a review July 9, 2025 07:37
@metalboyrick metalboyrick changed the title feat: add generic msg on failed transactions feat: add generic msg on failed transactions in toasts Jul 9, 2025
@metalboyrick
metalboyrick merged commit 15876d2 into Scaffold-Stark:develop Jul 9, 2025
1 check passed
@Jonatan-Chaverri
Jonatan-Chaverri deleted the better_error_msg_handling branch July 10, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better Error Message Handling on Failed Transactions

3 participants