Conversation
Add missing returns in generated close() paths, chain .catch on the Locations mixin callback test (matching the IAM/operations sites), and use const for routingParameter. Fixes #9432.
There was a problem hiding this comment.
Code Review
This pull request updates the TypeScript GAPIC generator templates for both CommonJS (CJS) and ECMAScript Modules (ESM), subsequently regenerating a large number of baseline files. The modifications include changing routingParameter from let to const, adding explicit return statements inside client close callbacks and test assertions, and appending .catch handlers to client calls within test promises. The reviewer identified a critical issue in both the CJS and ESM test templates: throwing an error asynchronously inside a .catch block within a new Promise executor does not reject the outer promise, causing it to hang indefinitely. To resolve this, the reviewer recommends replacing .catch(err => {throw err}) with .catch(reject) to properly propagate errors.
Throwing from the .catch handler inside a new Promise executor leaves the outer promise pending; pass reject instead. Applied to all three mixin callback tests (IAM, Locations, operations) in cjs and esm.
|
@gemini-code-assist please review! |
There was a problem hiding this comment.
Code Review
This pull request updates the TypeScript GAPIC generator templates (both CJS and ESM) and regenerates the corresponding baseline files. The modifications include adding explicit return; statements inside callbacks, changing let routingParameter to const, and refactoring promise rejections to use .catch(reject). The feedback highlights an issue in the test templates where throwing an error inside a .catch() block in callback-based tests (using done) can cause timeouts; chaining .catch(done) is recommended to ensure tests fail cleanly and immediately.
| client.{{ id.get("close") }}().then(() => { | ||
| done(); | ||
| return; | ||
| }).catch(err => {throw err}); |
There was a problem hiding this comment.
In callback-based tests (using done), throwing an error inside a .catch() block can cause the test to timeout rather than failing immediately with the actual error. Chaining .catch(done) instead ensures that any rejection is passed directly to the callback, failing the test cleanly and immediately.
client.{{ id.get(\"close\") }}().then(() => {\n done();\n return;\n }).catch(done);
| client.{{ id.get("close") }}().then(() => { | ||
| done(); | ||
| return; | ||
| }).catch(err => {throw err}); |
There was a problem hiding this comment.
In callback-based tests (using done), throwing an error inside a .catch() block can cause the test to timeout rather than failing immediately with the actual error. Chaining .catch(done) instead ensures that any rejection is passed directly to the callback, failing the test cleanly and immediately.
client.{{ id.get(\"close\") }}().then(() => {\n done();\n return;\n }).catch(done);
| client.{{ id.get("close") }}().then(() => { | ||
| done(); | ||
| return; | ||
| }).catch(err => {throw err}); |
There was a problem hiding this comment.
In callback-based tests (using done), throwing an error inside a .catch() block can cause the test to timeout rather than failing immediately with the actual error. Chaining .catch(done) instead ensures that any rejection is passed directly to the callback, failing the test cleanly and immediately.
client.{{ id.get(\"close\") }}().then(() => {\n done();\n return;\n }).catch(done);
| client.{{ id.get("close") }}().then(() => { | ||
| done(); | ||
| return; | ||
| }).catch(err => {throw err}); |
There was a problem hiding this comment.
In callback-based tests (using done), throwing an error inside a .catch() block can cause the test to timeout rather than failing immediately with the actual error. Chaining .catch(done) instead ensures that any rejection is passed directly to the callback, failing the test cleanly and immediately.
client.{{ id.get(\"close\") }}().then(() => {\n done();\n return;\n }).catch(done);
Fixes #9432. Unblocks the
prefer-const/no-floating-promiseshalf of the.eslintrc.jsonoverride added in #9429.Four template fixes (cjs + esm), plus regenerated baselines:
promise/always-returnreturn;in the clientclose()then-callbackpromise/always-returnreturn;in both generatedclose()testsno-floating-promises.catch(err => {throw err})on the Locations mixin callback test — its IAM and operations siblings already do thisprefer-constlet routingParameter→const(only everObject.assign-ed)Verification. Baselines are ESLint-ignored, so CI can't check this. I applied exactly these transformations to the real files that failed in #9427 and linted them with the four rules live:
Generator suite: 188 passing. Baseline diff is 240 files / 0 deletions, containing only
+ return;(350),let→const(12), and the 2 mixin.catchsites.Not sufficient on its own —
librarian.yamlpins the generator by tag + tarball checksum, so this needs a newgapic-generator-v*tag and alibrarian.yamlbump before the override lines can be dropped.