Skip to content

fix: better error messages for big instructions #2340

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

Merged
merged 6 commits into from
Feb 12, 2025

Conversation

guibescos
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Feb 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 1:46am
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 1:46am
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 1:46am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
component-library ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 1:46am
entropy-debugger ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 1:46am
insights ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 1:46am

if (!connection || !(await isPriceStoreInitialized(connection))) {
return
}
const handleSendProposalButtonClickAsync = async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just a copy paste refactor so we catch the promise error

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should remove the async marker from the outer function since it's no longer async.

Also, I generally recommend hoisting this kind of thing to the module scope and passing in arguments. For one, it avoids the perf overhead of creating closures at runtime. For two, it makes the code much easier to follow and understand. For three, explicitly passing arguments rather than relying on closure scoped variables makes the information flow much more obvious.

This function is already gigantic and really hard to trace and understand its flow, breaking it up outside the component would help a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the async keywork, but won't refactor since it's too much work

Copy link
Collaborator

@cprussin cprussin left a comment

Choose a reason for hiding this comment

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

Small stylistic nits but up to you if you think they're worth the effort

if (!connection || !(await isPriceStoreInitialized(connection))) {
return
}
const handleSendProposalButtonClickAsync = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should remove the async marker from the outer function since it's no longer async.

Also, I generally recommend hoisting this kind of thing to the module scope and passing in arguments. For one, it avoids the perf overhead of creating closures at runtime. For two, it makes the code much easier to follow and understand. For three, explicitly passing arguments rather than relying on closure scoped variables makes the information flow much more obvious.

This function is already gigantic and really hard to trace and understand its flow, breaking it up outside the component would help a lot.

) => {
const size = instruction.data.length
if (size > maxSize) {
throw new Error(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like in this case, you're just using exceptions for control flow. I generally recommend against this pattern, effectively this is a goto pattern in disguise. It's much better to refactor to use actual control flow constructs if it's not too much effort, but I get that this is a big chunk of old code so if it's not worth the effort that's fine too

Copy link
Contributor Author

@guibescos guibescos Feb 12, 2025

Choose a reason for hiding this comment

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

not worth the effort

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.

3 participants