Skip to content

Make safelyExecute type safe#3629

Merged
bergeron merged 9 commits intomainfrom
brian/typesafe-executes
Dec 10, 2023
Merged

Make safelyExecute type safe#3629
bergeron merged 9 commits intomainfrom
brian/typesafe-executes

Conversation

@bergeron
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread packages/controller-utils/src/util.ts Outdated
Comment thread packages/assets-controllers/src/NftController.ts Outdated
Comment thread packages/controller-utils/src/util.ts
Comment thread packages/controller-utils/src/util.ts
Comment thread packages/controller-utils/src/util.ts Outdated
Comment thread packages/controller-utils/src/util.ts Outdated
Comment thread packages/assets-controllers/src/TokenListController.ts
Copy link
Copy Markdown
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
@bergeron bergeron deleted the brian/typesafe-executes branch December 10, 2023 19:08
return {
...openSeaMetadata,
name: blockchainMetadata.name ?? openSeaMetadata?.name ?? null,
name: blockchainMetadata?.name ?? openSeaMetadata?.name ?? null,
Copy link
Copy Markdown
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
Copy Markdown
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