Skip to content

UnhandledPromiseRejectionWarning when using with bulk helper #19

Open
@zoellner

Description

@zoellner

The warning below is logged when using this lib with the es.helpers.bulk function

Sample code:

  const syncedAt = new Date().toISOString();
  const bulkResult = await es.helpers.bulk({
    datasource: [{syncedAt, id: '1'}],
    onDocument(doc) {
      return {index: {_index: 'test-index', _id: doc.id}};
    }
  });
  console.log(bulkResult);

Note that it works fine for other es requests, e.g. const searchResult = await es.search({index: 'test-index', body: {query: {match_all: {}}}});

I've debugged this a bit and it seems that even the most simple custom transport class using a promise will lead to this error which makes me think that the current approach with a promise inside the Transport.request function doesn't work

class CustomTransport extends Transport {
  request (params, options, callback) {
    new Promise((resolve) => {
      resolve();
    })
    .then(() => super.request(params, options, callback));
  }
}

The logged warning:

    at Object.then (/Users/zoellner/bc-books/bcb-server-api/node_modules/@elastic/elasticsearch/lib/Transport.js:337:18)
(node:36053) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:36053) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions