Unhandled promise rejection by Airtable javascript library

I would like to report a bug. Airtable javascript library has bad error handling when used with promises:
The following code demonstrates a wrong function call to table.create(). This function should be called with two parameters, and here I call it with one. Therefore, there should be some reasonable error message or the .catch section should be executed, but instead the program just hangs with the promise left unresolved forever.

At a later time, it would log an unclear warning UnhandledPromiseRejectionWarning. But the promise is still left unresolved.

Here is the sample code:

var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('YOUR_BASE_ID');
base('tablename').update({ "something": "wrong" })
  .then( (record) => console.log("never gets here.", record))
  .catch( (err) => console.error("never gets here neither", err) );

The full error message that appears in the log is:

(node:7969) UnhandledPromiseRejectionWarning: [object Object]
(node:7969) 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: 3)

I’m not 100% sure this is your issue, but then and catch shouldn’t be called with strings, they should be called with functions. Like this:

base('tablename').update({ "something": "wrong" })
  .then(() => {
    console.log("hello from `then`");
  })
  .catch((err) => {
    console.log("hello from `catch`");
    console.log("the error was", err);
  });

Does that help?

This is not the issue, but you are correct that my code example wasn’t clean. I’ve cleaned it now so my issue above should be clear to all readers. Thanks @EvanHahn

Thanks for that cleanup. This does seem like a small bug with Airtable.js. You should be able to fix this by calling the update method with the correct number of arguments, but we’ll see about fixing this in a future version of the library.

It is a small bug in the sense that it is easy to fix, and because it rarely happens.
But when it does happen, it is a programer’s nightmare, because the bogus error message is emitted to the log a few seconds after the call to Airtable, and therefore, in complex software systems, it takes days just to identify that the error is related to Airtable.
Thanks for considering fixing it in the next release.