aws-sdk-js: How to handle _hardError exceptions from s3.copyObject

When using s3.copyObject, if the original object doesn’t exist then aws-sdk throws an exception "NoSuchKey: The specified key does not exist.". I’d like to handle these gracefully, but try/catch blocks don’t work since the the exception is thrown outside the call stack.

Is there a correct way to handle this? Is it required to explicitly check the existence of the source object before calling s3.copyObject?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 16 (6 by maintainers)

Most upvoted comments

That’s odd, fs doesn’t crash an app if a file doesn’t exist. It actually uses the err in the callback. http doesn’t crash when you get on an URL that doesn’t exist… interesting.

\_(ツ)_/¯

Is this being looked at? Is there a workaround? To be clear, the problem is that this exception cannot be caught by the client code. This a fatal API bug. No API should throw an exception internally that is not caught internally. This will, at worst, simply crash the node app or, at best, will trigger a global exception handler to allow clean shutdown. Both of these are unacceptable for obvious reasons.

FWIW, I’m getting this issue with s3.getObject when an invalid key name is specified.