Repository navigation
[AI Improvement] [Task] Fix no-floating-promises in CLI command helpers (open, trackGA4, throttler, cloudbilling) - #11467
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces changes to handle unhandled promises when opening URLs and executing throttler tasks, including adding void operators, awaiting opn calls, and catching errors with debug logging. The reviewer recommends reusing the existing openInBrowser utility from src/utils.ts instead of calling the external open or opn libraries directly in hosting-channel-open.ts, open.ts, and cloudbilling.ts to maintain consistency and facilitate unit testing.
| open(channel.url).catch((err: unknown) => { | ||
| logger.debug(`Unable to open URL: ${getErrMsg(err)}`); | ||
| }); |
There was a problem hiding this comment.
Instead of importing and calling open directly from the open package, reuse the existing openInBrowser utility from src/utils.ts. This utility is specifically designed to wrap open so that it can be easily stubbed out in unit tests.
Please also update the imports at the top of the file to include openInBrowser from ../utils and remove the direct import of open.
| open(channel.url).catch((err: unknown) => { | |
| logger.debug(`Unable to open URL: ${getErrMsg(err)}`); | |
| }); | |
| openInBrowser(channel.url).catch((err: unknown) => { | |
| logger.debug("Unable to open URL: " + getErrMsg(err)); | |
| }); |
References
- Reuse or extend existing utilities: Check imported modules, the immediate subsystem, and
src/utils.tsfirst; reuse or extend existing helpers rather than writing bespoke inline logic. (link)
| open(url).catch((err: unknown) => { | ||
| logger.debug(`Unable to open URL: ${getErrMsg(err)}`); | ||
| }); |
There was a problem hiding this comment.
Instead of calling open directly, reuse the existing openInBrowser utility from src/utils.ts (which is already imported as utils in this file). This ensures consistency and allows the browser opening behavior to be stubbed out in unit tests.
You can also remove the unused import * as open from "open"; from the top of the file.
| open(url).catch((err: unknown) => { | |
| logger.debug(`Unable to open URL: ${getErrMsg(err)}`); | |
| }); | |
| utils.openInBrowser(url).catch((err: unknown) => { | |
| logger.debug("Unable to open URL: " + getErrMsg(err)); | |
| }); |
References
- Reuse or extend existing utilities: Check imported modules, the immediate subsystem, and
src/utils.tsfirst; reuse or extend existing helpers rather than writing bespoke inline logic. (link)
| if (open) { | ||
| try { | ||
| opn(url); | ||
| await opn(url); |
There was a problem hiding this comment.
Instead of calling opn directly, reuse the existing openInBrowser utility from src/utils.ts (which is already imported as utils in this file). This ensures consistency and allows the browser opening behavior to be stubbed out in unit tests.
You can also remove the unused import * as opn from "open"; from the top of the file.
| await opn(url); | |
| await utils.openInBrowser(url); |
References
- Reuse or extend existing utilities: Check imported modules, the immediate subsystem, and
src/utils.tsfirst; reuse or extend existing helpers rather than writing bespoke inline logic. (link)
Description
Fixes
@typescript-eslint/no-floating-promiseswarnings in CLI command and helper code (b/582885853, parent goal b/565072516):src/command.ts(validateProjectId): Mark fire-and-forgettrackGA4("error", ...)withvoid, matching existingvoid trackGA4(...)usage across the codebase.src/commands/open.ts&src/commands/hosting-channel-open.ts: Attach.catch((err: unknown) => { logger.debug(\Unable to open URL: ${getErrMsg(err)}`); })toopen(...)instead ofawaiting, so browser spawn failures (e.g., missingxdg-open`) log to debug rather than causing unhandled rejections or failing the command after printing the URL.src/gcp/cloudbilling.ts(openBillingAccount):await opn(url)inside the existingtry/catchblock so browser spawn failures reach the existinglogger.debughandler.src/throttler/throttler.ts(process()): Markvoid this.handle(this.nextWaitingTaskIndex())with an explanatory comment noting thathandle()records task success/failure itself andprocess()is intentionally synchronous to drive concurrency.Note:
src/commands/functions-log.ts:28(opn(url)) was intentionally left out of this PR to avoid a textual conflict with open PR #8211, which rewrites the sameif (options.open)block.Scenarios Tested
npx eslintwithout--quieton all 5 modified files: 0 errors, 0@typescript-eslint/no-floating-promiseswarnings, and 0 new warnings introduced.npx prettier --checkon all 5 modified files,npx tsc --noEmit -p tsconfig.json,npm run build,npm run test:compile, and full-reponpm run lint:quiet.src/throttler/throttler.spec.ts,src/throttler/queue.spec.ts,src/throttler/stack.spec.ts,src/gcp/cloudbilling.spec.ts,src/command.spec.ts): 78 passing, 2 pending, 0 failing.Sample Commands