top | item 40912567

(no title)

anytime5704 | 1 year ago

This makes me feel better about wasting the last 2 days debugging a failed unit test that was due to duplicate dependencies (with different versions).

  expect(mockDynamoDBClient).toHaveReceivedAnyCommand(); // passes
  expect(mockDynamoDBClient).toHaveReceivedCommand(UpdateCommand); // fails

  Received number of calls: 2
  Expected number of calls: >= 1
  Expected command: UpdateCommand

  Received commands:
    - UpdateCommand
    - UpdateCommand
I thought I was taking crazy pills.

discuss

order

asztal|1 year ago

This has happened to me multiple times with AWS SDK V3 (and other packages like react, cassandra-driver, etc.) and while there are ways to avoid it, it's not entirely simple to prevent.

Sadly, the most robust solution is often to use duck typing, e.g. instead of checking if the error is an instance of ResourceNotFoundError, check if error.code equals "ResourceNotFound" which works even if there are multiple library versions present. This is especially the case if you're writing a library that might be provided an instance of an AWS SDK v3 client, as it could be a different version.

I've been doing this stuff for 20 years so I'm used to it, I just feel bad for the novices.

anytime5704|1 year ago

Shit, I've been working for 10 years (but only a few months with these tools).

I actually considered the looser validation when I discovered that toHaveReceivedAnyCommand() worked, but, ultimately decided there *had* to be something wrong with my setup and I refused to leave it to hit someone else.

Shame the AWS SDK doesn't communicate the actual error in a more human readable way. I was legitimately questioning my sanity and/or the validity of the library for a minute there.