Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

triggers unhandled promise rejection that we cannot prevent #1319

@gsouf

Description

@gsouf

Environment details

  • OS: linux
  • Node.js version: 10
  • npm version: 7
  • @google-cloud/spanner version: 5.5.0

Steps to reproduce

Create this js file and run it (no need for a spanner instance to be setup).

This sample will try to connect to spanner with an unexisting instance name just because it's simpler to simulate the error this way, but it seems to occur with any error.. It will result in an error when doing the insert. The error will be caught in the catch statement, but it will also throw an unhandled promise rejection. The promise rejection that cannot be caught without unhandledRejection event is not a desired behavior for a 3rd party library.

const {Spanner} = require("@google-cloud/spanner");

run();

async function run() {
    try {
        const spanner = new Spanner({
            projectId: 'somebrokenprojectid',
        });

        const instance = spanner.instance("somebrokeninstance");
        const database = instance.database("somedb");

        const table =  database.table("sometable");

        console.log('insert data');

        await table.insert([{somekey: "somevalue"}]);
    } catch (e) {
        console.error('caught exception', e.message)
    }
}

Thanks

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/nodejs-spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions