Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix transaction async error handling that not thrown the full error #447

Conversation

neverlan
Copy link
Contributor

@neverlan neverlan commented Nov 21, 2018

Throw the full error in runTransactionAsync method instead of e.message.

Issue:
If you throw an error in the callback function, after a read for example, the error is misformatted.

Example:

    await db.runTransactionAsync(async (transaction) => {
      try {
        const [[invoice: { status }]] = await transaction.read('Invoices', {
          columns: ['status', 'invoiceId'],
          keys: [invoiceId],
          json: true,
        });
        if (status === "PAID") {
          const error = new Error('Cannot update Invoice as it is already paid');
          error.code = INVOICE_ALREADY_PAID
          error.status = 403;
          throw error;
        }
        // .......
       await transaction.commit();
      }
      catch (err) {
        // console.log(err.code) is undefined
        // console.log(err.status) is undefined
       next(err);
      }

Also in version 2.1.0, Transaction.ABORTED is undefined in the error handler (https://github.com/googleapis/nodejs-spanner/blob/master/src/database.ts#L1591), meaning the transaction was never retrieved in case of transient failure. It was fixed in #408. We should publish a new version whenever it's possible.

  • Tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Nov 21, 2018
@neverlan
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Nov 21, 2018
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Nov 26, 2018
@callmehiphop
Copy link
Contributor

@neverlan I went ahead and added some unit tests for this, if it looks good to you we'll get it merged!

@JustinBeckwith I think I'm going to need some help with the cla

@JustinBeckwith JustinBeckwith added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Nov 26, 2018
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@JustinBeckwith JustinBeckwith added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 26, 2018
@callmehiphop callmehiphop added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Nov 26, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 26, 2018
@JustinBeckwith JustinBeckwith merged commit a26ee6c into googleapis:master Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants