fix: run billing:usage's main() after its lookup tables initialize - #162
Open
mattbalza wants to merge 1 commit into
Open
fix: run billing:usage's main() after its lookup tables initialize#162mattbalza wants to merge 1 commit into
mattbalza wants to merge 1 commit into
Conversation
`pnpm billing:usage` throws `ReferenceError: Cannot access 'main' before initialization` on every run today. The call sits at line 10, above the `const` price and endpoint tables the function reads: `main` itself hoists, but those bindings are in their temporal dead zone until the module finishes evaluating. Moving the call to the end of the module is the whole fix — the script has no other entry point, and nothing after it depends on ordering.
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.
ReferenceError: Cannot access 'main' before initialization
pnpm billing:usagefails on every run today:await main()sits at line 10, above theconstprice and endpoint tables thefunction reads.
mainis a function declaration so it hoists, but thoseconstbindings stay in their temporal dead zone until the module finishes evaluating —
so the call is guaranteed to throw, not merely fragile.
The fix
Move the call to the end of the module. The script has no other entry point and
nothing after it depends on ordering, so this is the entire change.
Test plan
pnpm billing:usage # prints the account summary instead of throwing pnpm billing:usage --json=trueBoth hit only the free GET
/v3/appendix/user_dataendpoint, so verifying costsnothing.