Skip to content

chore(Client): robust error checking #9390

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 14 commits into from
Apr 17, 2023

Conversation

TetieWasTaken
Copy link
Contributor

@TetieWasTaken TetieWasTaken commented Apr 14, 2023

Please describe the changes this PR makes and why it should be merged:
Making this because branch at #9325 was messed up.

πŸ€– Generated by Copilot at ecb068b

Summary

πŸ“πŸ› οΈπŸš«

This pull request improves the error handling and validation of the Client constructor and its options. It adds a new custom error type InvalidScopeWithPermissions and a corresponding message template for when a bot requests a scope that requires permissions it does not have.

You tried to cheat the system with your scope
But the Client constructor saw your lie
Now you face the wrath of the InvalidScopeWithPermissions error
And your bot will never see the light

Walkthrough

  • Check that permissions option is only used with bot scope in Client constructor (packages/discord.js/src/client/Client.js) and throw DiscordjsTypeError with code InvalidScopeWithPermissions if not (link)
  • Check that allowedMentions, presence, ws, rest, and jsonTransformer options are of the expected types in Client constructor (packages/discord.js/src/client/Client.js) and throw DiscordjsTypeError with code ClientInvalidOption if not (link)
  • Add InvalidScopeWithPermissions property to ErrorCodes enum (packages/discord.js/src/errors/ErrorCodes.js) and keys array (link, link)
  • Add message template for InvalidScopeWithPermissions error code to Messages object (packages/discord.js/src/errors/Messages.js) (link)

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@vercel
Copy link

vercel bot commented Apr 14, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Apr 17, 2023 2:58pm
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Apr 17, 2023 2:58pm

@TetieWasTaken TetieWasTaken changed the title chore: robust error checking chore(Client): robust error checking Apr 15, 2023
@github-actions
Copy link

github-actions bot commented Apr 15, 2023

⚑️ Lighthouse report for the changes in this PR:

Category Score
🟒 Performance 90
🟒 Accessibility 100
🟒 Best practices 100
🟒 SEO 100
🟠 PWA 70

Lighthouse ran on https://discord-js-git-fork-tetiewastaken-chore-robust-errors-discordjs.vercel.app/

TetieWasTaken and others added 2 commits April 17, 2023 14:34
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
@TetieWasTaken TetieWasTaken requested a review from a team as a code owner April 17, 2023 12:34
Copy link
Member

@Jiralite Jiralite left a comment

Choose a reason for hiding this comment

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

DiscordjsErrorCodes needs updating in the typings.

@kodiakhq kodiakhq bot merged commit 7d7972d into discordjs:main Apr 17, 2023
@TetieWasTaken TetieWasTaken deleted the chore/robust-errors branch April 17, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants