fix: resolve TDZ race on getClient/getClientUser during ready event - #45
Open
SpackledJim wants to merge 1 commit into
Open
SpackledJim wants to merge 1 commit into
SpackledJim wants to merge 1 commit into
Conversation
discordActivities.ts imported a getClientUser helper from app.ts that either didn't exist (as shipped in 4.1.2) or, in a later partial fix on main, was exported after `await discordClient.login(token)` — so any `ready`-event handler calling it before that final line executed threw "Cannot access '...' before initialization" instead of setting the bot's activity. Move the `getClient` export up to immediately after the Client is constructed, before event handlers are registered or login() is called, so it's initialized before any event can fire. Derive the client user in discordActivities.ts via a local getClientUser() helper built on getClient().user instead of relying on a second export from app.ts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S9oMx1pYL6igWuytQyqSTa
Owner
|
You encounter this every time you run the container? Not to say this bug isn't real but I've never seen this issue and have had this connection logic in 'prod' for years |
Author
|
I did, yeah.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bot crashes on
ready:getClientUseraccessed before initializationCommit:
5a6e4c5—fix: resolve TDZ race on getClient/getClientUser during ready eventSymptom
After login, the bot exits on the
readyevent:Reproduced consistently on
4.1.2and4.2.0(Deno 2.5.6, Docker).Cause
app.tsexports its client accessors on the last lines of the module, afterawait discordClient.login(token). Thereadyhandler can run while thatawaitis pending, sodiscordActivities.tscalls the accessor before its binding is initialized. The circular import between the two modules is why this surfaces as a TDZ error.Fix
app.ts: moveexport const getClientto directly after the client is constructed, before handlers are registered andlogin()is called. Remove the trailinggetClientUserexport.discordActivities.ts: importgetClientand derive the user locally: