question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client-s3: GetObjectCommand with ETags throws error without name or details

See original GitHub issue

Describe the bug

When doing a GetObjectCommand with an IfNoneMatch: ETag in the request, the exception that is thrown is really unclear. It has an empty name and the message is just UnknownError.

When I tried to search documentation to understand what kind of errors I can receive from S3Client.send() I didn’t really find anything.

Expected Behavior

When trying to get a file with anIfNoneMatch: ETag (where ETag is the current ETag of the file) I expected to receive an error that I can easily identify to conclude that the file in S3 has not changed after I retrieved it the last time.

Current Behavior

The error I get is:

{
  "name": "",
  "$fault": "client",
  "$metadata": {
    "httpStatusCode": 304,
    "extendedRequestId": "Q8wEKZiI/bb6oeV68jmwv3yTmrTQRi30YpbA7QzcggSRJcU27YJgJDyGBLp14NTu2n8/FNPDQj0=",
    "attempts": 1,
    "totalRetryDelay": 0
  },
  "message": "UnknownError"
}

Reproduction Steps

import { S3Client, GetObjectCommand, GetObjectCommandInput, GetObjectCommandOutput } from "@aws-sdk/client-s3";

const params: GetObjectCommandInput = {
  Bucket: 'my-bucket',
  Key: 'my-key.gz',
  IfNoneMatch: '<existing etag for the file>'
}
const command = new GetObjectCommand(params);
const s3 = new S3Client();
try {
  const resp = await s3.send(command);
} catch (e) {
  console.log(JSON.stringify(e, null, 2))
}

Possible Solution

If the received exception is as intended, there should at least be some documentation on what kind of exceptions can be thrown.

Additional Information/Context

Appears similar as https://github.com/aws/aws-sdk-js-v3/issues/1596

SDK version used

3.105.0

Environment details (OS name and version, etc.)

Mac OS, typescript 4.7.3

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
AllanZhengYPcommented, Jun 27, 2022

Hi @terozio

I can confirm the S3 returns a 304 with empty payload with the input you shared. In this case the SDK cannot parse a valid error code(name) from the response. In v2 SDK, we use the error status code directly. I think the same applies to the v3 SDK too.

Since this 304 error is not modeled in the service API model, the SDK doesn’t generate a named error class for it, hense you cannot assert this specific error. As mentioned in the blog, it’s safer to always have a fallback error assertion in the catch statements like (e instanceof S3ServiceException) {}.

I will work on a fix to populate the status case as error name, to improve the visibility of the error cause(in this case it’s the 304 redirection). The caught error will look like:

{
  "name": "304",
  "$fault": "client",
  "$metadata": {
    "httpStatusCode": 304,
    "extendedRequestId": "Q8wEKZiI/bb6oeV68jmwv3yTmrTQRi30YpbA7QzcggSRJcU27YJgJDyGBLp14NTu2n8/FNPDQj0=",
    "attempts": 1,
    "totalRetryDelay": 0
  },
  "message": "UnknownError"
}
0reactions
github-actions[bot]commented, Jul 15, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get response from S3 getObject in Node.js?
log s, my IDE (NetBeans) throws an error and refuses to show the value of data. While this could just be the IDE,...
Read more >
GetObjectCommand | S3 Client - AWS SDK for JavaScript v3
Retrieves objects from Amazon S3. To use GET , you must have READ access to the object. If you grant READ access to...
Read more >
S3 — Boto3 Docs 1.26.37 documentation - Amazon AWS
Anonymous requests are never allowed to create buckets. By creating the bucket, you become the bucket owner. Not every string is an acceptable...
Read more >
get the path of image from the aws s3 bucket nodejs - You.com
getObject({ Bucket: "BucketName", Key: "ETag.jpeg" }, function(error, ... const { GetObjectCommand, S3Client } = require('@aws-sdk/client-s3') const client ...
Read more >
@aws-sdk/client-s3 - npm
Description. AWS SDK for JavaScript S3 Client for Node.js, Browser and React Native. Installing. To install the this package ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found