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

Make safelyExecute type safe #3629

Merged
merged 9 commits into from
Dec 10, 2023
Merged

Make safelyExecute type safe #3629

merged 9 commits into from
Dec 10, 2023

Conversation

bergeron
Copy link
Contributor

@bergeron bergeron commented Dec 6, 2023

Explanation

safelyExecute and safelyExecuteWithTimeout are convenient utility functions, but they were returning any which removes type safety. This PR makes them generic so they return the type of the underlying operation.

References

Changelog

@metamask/controller-utils

  • BREAKING: Make safelyExecute and safelyExecuteWithTimeout generic so they preserve types

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@bergeron bergeron requested a review from a team as a code owner December 6, 2023 21:25
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Thanks, this makes sense! Could you mark this as a breaking change for both safelyExecute and safelyExecuteWithTimeout in the PR description? I've also left a couple of comments and a question.

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

This looks good to me!

@bergeron bergeron merged commit 27047d2 into main Dec 10, 2023
136 checks passed
@bergeron bergeron deleted the brian/typesafe-executes branch December 10, 2023 19:08
@@ -520,13 +520,13 @@ export class NftController extends BaseControllerV1<NftConfig, NftState> {

return {
...openSeaMetadata,
name: blockchainMetadata.name ?? openSeaMetadata?.name ?? null,
name: blockchainMetadata?.name ?? openSeaMetadata?.name ?? null,
Copy link
Member

Choose a reason for hiding this comment

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

@bergeron How would you describe the impact of these changes? It looks like they'd have a functional impact.

This suggests that there may have been cases where blockchainMetadata was nullish, which previously would have thrown an error on this line. But now it's no longer thrown.

Similarly, below in getNftContractInformation, the changes suggest that address and contract.name would previously be missing sometimes, but now they're always included.

Is that the case? Or are the affected scenarios really non-existent, with these changes being made just for type reasons.

Copy link
Member

@Gudahtt Gudahtt Dec 14, 2023

Choose a reason for hiding this comment

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

It looks like this does fix something. In the case where the request fails, this would crash on this line previously, but now it doesn't.

Too bad this isn't represented in tests either, there are no tests for this method (as it's private). And even indirect uses of it are stubbed out in the tests 🤦

@Gudahtt Gudahtt mentioned this pull request Dec 14, 2023
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.

4 participants