Skip to content

Conversation

@alkatrivedi
Copy link
Contributor

@alkatrivedi alkatrivedi commented Dec 15, 2025

This PR fixes a TypeScript compilation error in the Snapshot.run method.

The problem

1. Type Mismatch: The RunCallback expects a ServiceError (with code, metadata, etc.), but the Node.js stream error event is typed to emit a generic Error. This caused a compilation failure: Argument of type 'Error' is not assignable to parameter of type 'ServiceError'

2. Undefined Variables as a argument: The .on('error', (err, rows, stats, metadata) => ...) handler was declaring rows, stats, and metadata as arguments. Since the standard error event only emits a single argument (err), these variables were always undefined inside the handler

The Fix

1. Removed undefined arguments: The error handler now only accepts (err). This allows the closure to access the correct rows, stats, and metadata variables from the outer scope, ensuring that partial results collected before the error are correctly passed to the user

2. Added Type Cast: Explicitly cast err to ServiceError. In the context of the Spanner client, runtime errors from the stream are expected to be ServiceError objects, making this cast safe and compatible with our callback signature

@alkatrivedi alkatrivedi requested review from a team as code owners December 15, 2025 07:44
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: spanner Issues related to the googleapis/nodejs-spanner API. labels Dec 15, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @alkatrivedi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a TypeScript compilation error within the Snapshot.run method's error handling. It addresses a type mismatch where a generic Error was being passed to a callback expecting a ServiceError, and cleans up unused parameters in the error handler. The changes ensure type safety and correct propagation of partial results and error information in the Spanner client's stream processing.

Highlights

  • Type Mismatch Resolution: Fixed a TypeScript compilation error where the RunCallback expected a ServiceError but the Node.js stream error event emitted a generic Error.
  • Argument Cleanup: Removed 'rows', 'stats', and 'metadata' from the error handler's arguments, as they were always undefined and caused issues.
  • Type Casting: Introduced an explicit type cast (err as ServiceError) to ensure type compatibility with the RunCallback signature, leveraging the expectation that runtime errors from the Spanner client are ServiceError objects.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a TypeScript compilation error and a bug in the Snapshot.run error handler. By adjusting the error handler signature to only accept the err parameter, it now correctly uses the rows, stats, and metadata from the outer scope. The explicit cast to ServiceError resolves the type mismatch. However, I have a suggestion to make this cast safer to handle cases where a non-ServiceError might be emitted by the stream pipeline.

setSpanError(span, err);
span.end();
callback!(err, rows, stats, metadata);
callback!(err as ServiceError, rows, stats, metadata);

Choose a reason for hiding this comment

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

high

While it's true that most errors from the stream will be ServiceError instances, it's possible for other parts of the stream processing pipeline to emit a generic Error. For example, partial-result-stream.ts can emit a plain Error if it fails to resume after multiple retries.

The cast err as ServiceError is unsafe in that case and could lead to runtime errors in user code if they try to access properties like code or metadata on what they believe is a ServiceError.

To make this safer, we should ensure the error object conforms to the ServiceError interface before passing it to the callback.

            if (!('code' in err)) {
              Object.assign(err, {
                code: grpc.status.UNKNOWN,
                details: err.message,
                metadata: new grpc.Metadata(),
              });
            }
            callback!(err as ServiceError, rows, stats, metadata);

@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Dec 15, 2025
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Dec 15, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 15, 2025
@alkatrivedi alkatrivedi merged commit 4ac0360 into main Dec 15, 2025
23 of 24 checks passed
@alkatrivedi alkatrivedi deleted the fix-presubmit branch December 15, 2025 12:13
gcf-merge-on-green bot pushed a commit that referenced this pull request Jan 9, 2026
🤖 I have created a release *beep* *boop*
---


## [8.4.0](https://togithub.com/googleapis/nodejs-spanner/compare/v8.3.1...v8.4.0) (2026-01-09)


### Features

* Add a ClientContext field to Spanner requests ([#2493](https://togithub.com/googleapis/nodejs-spanner/issues/2493)) ([37504ad](https://togithub.com/googleapis/nodejs-spanner/commit/37504adcc37a7e95acfb2530313ff783d0c1fe7d))
* Exposing total CPU related fields in AutoscalingConfig ([#2490](https://togithub.com/googleapis/nodejs-spanner/issues/2490)) ([508f0ff](https://togithub.com/googleapis/nodejs-spanner/commit/508f0ff95636b004f4200522018a199263eda8ca))
* **spanner:** Support for type UUID ([#2482](https://togithub.com/googleapis/nodejs-spanner/issues/2482)) ([0047e94](https://togithub.com/googleapis/nodejs-spanner/commit/0047e9407d86521571626c69011b70307f83f8ba))


### Bug Fixes

* **deps:** Update dependency google-gax to v5.0.6 ([#2452](https://togithub.com/googleapis/nodejs-spanner/issues/2452)) ([f9e6b86](https://togithub.com/googleapis/nodejs-spanner/commit/f9e6b86ff4da03110642c17e5ebc8fac8d903d3a))
* Flaky metric test ([#2472](https://togithub.com/googleapis/nodejs-spanner/issues/2472)) ([e169cc5](https://togithub.com/googleapis/nodejs-spanner/commit/e169cc5344d38812b1ebf20c7a987715a73d6f79))
* Memory leak and deadlock due to error event in multiplexed session ([#2477](https://togithub.com/googleapis/nodejs-spanner/issues/2477)) ([c624619](https://togithub.com/googleapis/nodejs-spanner/commit/c624619a3960892b1d2d412ff79faa5a74de45df))
* Presubmit failure for samples backups test ([#2492](https://togithub.com/googleapis/nodejs-spanner/issues/2492)) ([01eb3d5](https://togithub.com/googleapis/nodejs-spanner/commit/01eb3d5801ddb21517f185b9d585fbce4fa1475c))
* Type check for key in deleteRows ([#2486](https://togithub.com/googleapis/nodejs-spanner/issues/2486)) ([7347a16](https://togithub.com/googleapis/nodejs-spanner/commit/7347a1628ad8635b8f84b36ad1d3850b78862ac7))
* Type mismatch in Snapshot.run error handler ([#2487](https://togithub.com/googleapis/nodejs-spanner/issues/2487)) ([4ac0360](https://togithub.com/googleapis/nodejs-spanner/commit/4ac036047e3a03c073300f288c746389a38d8e42))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/nodejs-spanner API. kokoro:force-run Add this label to force Kokoro to re-run the tests. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants